This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Wrong snprintf optimalization
- From: Martin Sebor <msebor at gmail dot com>
- To: Dávid Bolvanský <david dot bolvansky at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 23 Apr 2018 02:05:40 -0600
- Subject: Re: Wrong snprintf optimalization
- References: <CAOrgDVNwKLLEnW6fpV3p0pw8Pk=vvxQF+phff-cdHLh1dey9nQ@mail.gmail.com>
[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