diff options
author | Kevin Ryde <user42@zip.com.au> | 2001-08-16 01:51:14 +0200 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2001-08-16 01:51:14 +0200 |
commit | 537a2637837a0bcdc586967796cf1a8eecfa2465 (patch) | |
tree | 5e2c49a50924fea7837c5c6c30a7fa04f5ac40f9 /printf | |
parent | 980c727c0ca0524481d4094b6cdc840d0029568e (diff) | |
download | gmp-537a2637837a0bcdc586967796cf1a8eecfa2465.tar.gz |
* printf/snprntffuns.c (gmp_snprintf_format): Correction to bufsize-1
return value handling.
Was overwriting d->size before finished with the old value. Showed up
as gmp_vsnprintf failures on glibc 2.0.7 and irix 6.
Diffstat (limited to 'printf')
-rw-r--r-- | printf/snprntffuns.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/printf/snprntffuns.c b/printf/snprntffuns.c index 43b603127..c26ed9cf2 100644 --- a/printf/snprntffuns.c +++ b/printf/snprntffuns.c @@ -52,25 +52,26 @@ MA 02111-1307, USA. */ static int gmp_snprintf_format (struct gmp_snprintf_t *d, const char *fmt, va_list ap) { - int ret, step, alloc; + int ret, step, alloc, avail; char *p; ASSERT (d->size >= 0); - if (d->size > 1) + avail = d->size; + if (avail > 1) { - ret = vsnprintf (d->buf, d->size, fmt, ap); + ret = vsnprintf (d->buf, avail, fmt, ap); if (ret == -1) { - ASSERT (strlen (d->buf) == d->size-1); - ret = d->size-1; + ASSERT (strlen (d->buf) == avail-1); + ret = avail-1; } - step = MIN (ret, d->size-1); + step = MIN (ret, avail-1); d->size -= step; d->buf += step; - if (ret != d->size-1) + if (ret != avail-1) return ret; /* probably glibc 2.0.x truncated output, probe for actual size */ |