diff options
| author | Linus Torvalds <torvalds@penguin.transmeta.com> | 2002-06-11 22:51:39 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@penguin.transmeta.com> | 2002-06-11 22:51:39 -0700 |
| commit | 95bd6a7926f7bb479e024e7baca9c751914a04cf (patch) | |
| tree | db1d6ae60879b59bfa2d76a2146c34768352ffda /lib/vsprintf.c | |
| parent | 82edfcdc876d96fc60e97d9a265f97905b111001 (diff) | |
revert to correct C99 behaviour
Cset exclude: bcrl@redhat.com|ChangeSet|20020429021546|12619
Diffstat (limited to 'lib/vsprintf.c')
| -rw-r--r-- | lib/vsprintf.c | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index bef44de31d2a..03bced06b292 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -172,41 +172,50 @@ static char * number(char * buf, char * end, long long num, int base, int size, if (!(type&(ZEROPAD+LEFT))) { while(size-->0) { if (buf <= end) - *buf++ = ' '; + *buf = ' '; + ++buf; } } if (sign) { if (buf <= end) - *buf++ = sign; + *buf = sign; + ++buf; } if (type & SPECIAL) { if (base==8) { if (buf <= end) - *buf++ = '0'; + *buf = '0'; + ++buf; } else if (base==16) { if (buf <= end) - *buf++ = '0'; + *buf = '0'; + ++buf; if (buf <= end) - *buf++ = digits[33]; + *buf = digits[33]; + ++buf; } } if (!(type & LEFT)) { while (size-- > 0) { if (buf <= end) - *buf++ = c; + *buf = c; + ++buf; } } while (i < precision--) { if (buf <= end) - *buf++ = '0'; + *buf = '0'; + ++buf; } while (i-- > 0) { if (buf <= end) - *buf++ = tmp[i]; + *buf = tmp[i]; + ++buf; } while (size-- > 0) { if (buf <= end) - *buf++ = ' '; + *buf = ' '; + ++buf; } return buf; } @@ -238,10 +247,6 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) /* 'z' support added 23/7/1999 S.H. */ /* 'z' changed to 'Z' --davidm 1/25/99 */ - /* Enforce absolute minimum size: one character + the trailing 0 */ - if (size < 2) - return 0; - str = buf; end = buf + size - 1; @@ -253,7 +258,8 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) for (; *fmt ; ++fmt) { if (*fmt != '%') { if (str <= end) - *str++ = *fmt; + *str = *fmt; + ++str; continue; } @@ -317,15 +323,18 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) if (!(flags & LEFT)) { while (--field_width > 0) { if (str <= end) - *str++ = ' '; + *str = ' '; + ++str; } } c = (unsigned char) va_arg(args, int); if (str <= end) - *str++ = c; + *str = c; + ++str; while (--field_width > 0) { if (str <= end) - *str++ = ' '; + *str = ' '; + ++str; } continue; @@ -339,16 +348,19 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) if (!(flags & LEFT)) { while (len < field_width--) { if (str <= end) - *str++ = ' '; + *str = ' '; + ++str; } } for (i = 0; i < len; ++i) { if (str <= end) - *str++ = *s++; + *str = *s; + ++str; ++s; } while (len < field_width--) { if (str <= end) - *str++ = ' '; + *str = ' '; + ++str; } continue; @@ -380,7 +392,8 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) case '%': if (str <= end) - *str++ = '%'; + *str = '%'; + ++str; continue; /* integer number formats - set up the flags and "break" */ @@ -402,10 +415,12 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) default: if (str <= end) - *str++ = '%'; + *str = '%'; + ++str; if (*fmt) { if (str <= end) - *str++ = *fmt; + *str = *fmt; + ++str; } else { --fmt; } |
