This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Wrong snprintf optimalization


[BCC gcc-bugs@gcc.gnu.org]

On 04/21/2018 03:47 AM, Dávid Bolvanský wrote:
Hello,

#include <math.h>
int main(void)
{
char buf[10];
return snprintf(buf, 0, "string");
}

GCC simplifies it to
main:
mov eax, 6
ret

but 0 is correct I think.

Please use Bugzilla to report problems and post questions to
gcc-help.  This is list is a Bugzilla reflector (it collects
Bugzilla traffic).

The snprintf function returns the number of characters that
would have been written had n been sufficiently large so
GCC's behavior is correct.

Besides the C standard a normative description of snprintf
can be found in POSIX:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/snprintf.html

Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]