summaryrefslogtreecommitdiff
path: root/src/vsnprintf.c
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2005-08-11 00:36:51 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2005-08-11 00:36:51 +0000
commiteeda8ef60b8c8040c64b07e44b0be6c92a38c907 (patch)
treee2c1da77392d96fc4f8ed9cb26d27747f905f88a /src/vsnprintf.c
parentaf39242da6b5aa97ecbe4d197b1698906b347689 (diff)
Add support for * width and precision values, and fix potential
infinite loop bug... git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4504 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/vsnprintf.c')
-rw-r--r--src/vsnprintf.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/vsnprintf.c b/src/vsnprintf.c
index e2f39888e..acf9d6c0a 100644
--- a/src/vsnprintf.c
+++ b/src/vsnprintf.c
@@ -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') {
@@ -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 ++;
}
}