Skip to content

Commit

Permalink
Add support for * width and precision values, and fix potential
Browse files Browse the repository at this point in the history
infinite loop bug...


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4504 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
michaelrsweet committed Aug 11, 2005
1 parent af39242 commit eeda8ef
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/vsnprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,26 @@ int fl_vsnprintf(char* buffer, size_t bufsize, const char* format, va_list ap) {
} else if (strchr(" -+#\'", *format)) sign = *format++;
else sign = 0;

width = 0;
while (isdigit(*format & 255)) width = width * 10 + *format++ - '0';
if (*format == '*') {
// Get width from argument...
format ++;
width = va_arg(ap, int);
} else {
width = 0;
while (isdigit(*format & 255)) width = width * 10 + *format++ - '0';
}

if (*format == '.') {
format ++;
prec = 0;

while (isdigit(*format & 255)) prec = prec * 10 + *format++ - '0';
if (*format == '*') {
// Get precision from argument...
format ++;
prec = va_arg(ap, int);
} else {
prec = 0;
while (isdigit(*format & 255)) prec = prec * 10 + *format++ - '0';
}
} else prec = -1;

if (*format == 'l' && format[1] == 'l') {
Expand Down Expand Up @@ -236,7 +248,8 @@ int fl_vsnprintf(char* buffer, size_t bufsize, const char* format, va_list ap) {
} else {
bytes ++;

if (bufptr && bufptr < bufend) *bufptr++ = *format++;
if (bufptr && bufptr < bufend) *bufptr++ = *format;
format ++;
}
}

Expand Down

0 comments on commit eeda8ef

Please sign in to comment.