Bug#22541: Better info on snprintf bug
Giuliano P Procida <gpp10@cam.ac.uk> writes:
>
> Here is some more! Please ignore previous witterings which indicated
> that I had forgotten that size_t is unsigned!
>
> #include <stdio.h>
> #include <stdarg.h>
> int main () {
> char b[9];
> int stat;
> int i;
> for (i = 0; i < 5; ++i) {
> stat = snprintf (b, i, "foo");
> printf ("i %u, got %d, exp %d\n", i, stat, (size_t) i < 4 ? -1 : 3);
> }
> for (i = -1; i < 5; ++i) {
> stat = snprintf (b, i, "foo");
> printf ("i %u, got %d, exp %d\n", i, stat, (size_t) i < 4 ? -1 : 3);
> }
> return 0;
> }
>
> i 0, got 0, exp -1 <- sick
> i 1, got -1, exp -1 <- works OK
> i 2, got -1, exp -1
> i 3, got -1, exp -1
> i 4, got 3, exp 3
> i 4294967295, got 3, exp 3 <- throw in MAX_UINT
> i 0, got 0, exp -1 <- sick
> i 1, got 3, exp -1 <- BROKEN this time
> i 2, got -1, exp -1
> i 3, got -1, exp -1
> i 4, got 3, exp 3
I just gave snprintf() a try in libc6 2.1.2-11 and it now returns 3 in
all the above cases, which is correct per the change to ISO C9x
described in the info docs for snprintf(), so I think this bug could
be closed.
Reply to: