Skip to contentSkip to conversation

common/vsprintf: fix return value when formatting symbolic addresses

PATCH In review Jan Beulich 3 participants 3 messages Dec 2, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/vsprintf: fix return value when formatting symbolic addresses

When the buffer to be formatted to is too small, the function return value is expected to be the number of characters that would be printed (particularly important if that value is then used for allocating a buffer). Hence incrementing the active pointer must always be independent of actually storing a character.

xen/common/vsprintf.c +2 -1
@@ -294,6 +294,7 @@ static char *pointer(char *str, char *en
             /* Print '+<offset>/<len>' */
             str = number(str, end, sym_offset, 16, -1, -1, SPECIAL|SIGN|PLUS);
             if ( str <= end )
-                *str++ = '/';
+                *str = '/';
+            ++str;
             str = number(str, end, sym_size, 16, -1, -1, SPECIAL);
         }

common/vsprintf: fix return value when formatting symbolic addresses

When the buffer to be formatted to is too small, the function return value is expected to be the number of characters that would be printed (particularly important if that value is then used for allocating a buffer). Hence incrementing the active pointer must always be independent of actually storing a character.

xen/common/vsprintf.c +2 -1
@@ -294,6 +294,7 @@ static char *pointer(char *str, char *en
             /* Print '+<offset>/<len>' */
             str = number(str, end, sym_offset, 16, -1, -1, SPECIAL|SIGN|PLUS);
             if ( str <= end )
-                *str++ = '/';
+                *str = '/';
+            ++str;
             str = number(str, end, sym_size, 16, -1, -1, SPECIAL);
         }

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jan Beulich

When the buffer to be formatted to is too small, the function return value is expected to be the number of characters that would be printed (particularly important if that value is then used for allocating a buffer). Hence incrementing the active pointer must always be independent of actually storing a character.

Quoted 16 lines
xen/common/vsprintf.c +2 -1
@@ -294,6 +294,7 @@ static char *pointer(char *str, char *en
             /* Print '+<offset>/<len>' */
             str = number(str, end, sym_offset, 16, -1, -1, SPECIAL|SIGN|PLUS);
             if ( str <= end )
-                *str++ = '/';
+                *str = '/';
+            ++str;
             str = number(str, end, sym_size, 16, -1, -1, SPECIAL);
         }
Acked-by
#2 lore raw
Quoted 10 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich

When the buffer to be formatted to is too small, the function return value is expected to be the number of characters that would be printed (particularly important if that value is then used for allocating a buffer). Hence incrementing the active pointer must always be independent of actually storing a character.

Quoted 19 lines
Quoted 17 lines
xen/common/vsprintf.c +2 -1
@@ -294,6 +294,7 @@ static char *pointer(char *str, char *en
             /* Print '+<offset>/<len>' */
             str = number(str, end, sym_offset, 16, -1, -1,
 SPECIAL|SIGN|PLUS);
             if ( str <= end )
-                *str++ = '/';
+                *str = '/';
+            ++str;
             str = number(str, end, sym_size, 16, -1, -1, SPECIAL);
         }