Skip to content

Commit

Permalink
LOG: Observe field widths when serializing string arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
beekhof committed Jun 7, 2012
1 parent 3369581 commit 9b0bb4e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/log_format.c
Expand Up @@ -386,6 +386,7 @@ qb_vsprintf_serialize(char *serialize, const char *fmt, va_list ap)
uint32_t location = 0;
int type_long = 0;
int type_longlong = 0;
int sformat_length = 0;

p = stpcpy(serialize, fmt);
location = p - serialize + 1;
Expand All @@ -408,6 +409,8 @@ qb_vsprintf_serialize(char *serialize, const char *fmt, va_list ap)
case '\'': /* group in thousands, ignore */
case 'I': /* glibc-ism locale alternative, ignore */
case '.': /* precision, ignore */
format++;
goto reprocess;
case '0': /* field width, ignore */
case '1': /* field width, ignore */
case '2': /* field width, ignore */
Expand All @@ -418,6 +421,8 @@ qb_vsprintf_serialize(char *serialize, const char *fmt, va_list ap)
case '7': /* field width, ignore */
case '8': /* field width, ignore */
case '9': /* field width, ignore */
sformat_length *= 10;
sformat_length += (format[0] - '0');
format++;
goto reprocess;

Expand Down Expand Up @@ -505,6 +510,9 @@ qb_vsprintf_serialize(char *serialize, const char *fmt, va_list ap)
arg_string = va_arg(ap, char *);
if (arg_string == NULL) {
p = stpcpy(&serialize[location], "(null)");
} else if (sformat_length) {
p = stpncpy(&serialize[location], arg_string, sformat_length);
serialize[location+sformat_length] = 0;
} else {
p = stpcpy(&serialize[location], arg_string);
}
Expand All @@ -520,6 +528,7 @@ qb_vsprintf_serialize(char *serialize, const char *fmt, va_list ap)
}
case '%':
serialize[location++] = '%';
sformat_length = 0;
break;

}
Expand Down

0 comments on commit 9b0bb4e

Please sign in to comment.