Skip to contentSkip to conversation

printf("%n" behavior on overflow

PATCH New Samuel Thibault 1 participant 1 message Dec 28, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 printf("%n" behavior on overflow

Hello,

In C99 (7.19.6.2.10), the behavior of scanf("stuff... %n", ..., &n) is said to be undefined if the value to be put is n can't fit. I guess we can safely consider that the same applies to printf.

extras/mini-os/lib/printf.c +0 -2
diff -r 5da126f8960e -r 077f5106d691 extras/mini-os/lib/printf.c
@@ -426,8 +426,6 @@ int vsnprintf(char *buf, size_t size, co
 
 
         case 'n':
-            /* FIXME:
-             * What does C99 say about the overflow case here? */
             if (qualifier == 'l') {
                 long * ip = va_arg(args, long *);
                 *ip = (str - buf);