Re: Wrong snprintf optimalization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[BCC gcc-bugs@xxxxxxxxxxx]

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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux