From: Fabio N. <f.n...@gm...> - 2007-07-12 21:18:51
|
First of all, hi to everyone because this is my first message. I think that I've found a bug, or maybe I'just think wrong. Before I sumbit a bug report i ask in this list. Here is the code: #include <stdio.h> #include <string.h> #define BIG_STRING "qwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiop" int main() { =09char buf[12]; =09int written; =09written =3D snprintf(buf, sizeof(buf), "%s", BIG_STRING); =09printf("Content is: %s\nlength is %d\nwritten is %d\n", buf, strlen(buf), written); =09return 0; } and here is the result: Content is: qwertyuiopqw=BF " length is 15 written is -1 Now from man snprintf I read: "The snprintf() and vsnprintf() functions will write at most size-1 of the characters printed into the output string (the size'th character then gets the terminating `\0'); if the return value is greater than or equal to the size argument, the string was too short and some of the printed characters were discarded. The output is always null-terminated." Therefore the correct output should be: Content is: qwertyuiopq length is 11 written is -1 I've tried this code on my Asus Notebook with WindowsXP and the last, just updated, mingw version. The result is the same on another PC with Win2k and an older version of Mingw. Can anyone could explain me what's wrong? --=20 Fabio Napoleoni f.n...@gm... "Computer Science is no more about computers than astronomy is about telescopes" Edsger W. Dijkstra |