summaryrefslogtreecommitdiff
path: root/printf/snprntffuns.c
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2001-07-30 23:16:38 +0200
committerKevin Ryde <user42@zip.com.au>2001-07-30 23:16:38 +0200
commit721064adc872c6d272bb6e1a44caa147fb674537 (patch)
treebb59ab392289ebf752672cd2826cc4ea36934f8d /printf/snprntffuns.c
parent73878ea7d9c1ee1f55f0ba168a2d6d4cbcdfe0b5 (diff)
downloadgmp-721064adc872c6d272bb6e1a44caa147fb674537.tar.gz
More of initial checkin.
(Allow vsnprintf return -1, per old glibc.)
Diffstat (limited to 'printf/snprntffuns.c')
-rw-r--r--printf/snprntffuns.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/printf/snprntffuns.c b/printf/snprntffuns.c
index e761aef64..6603e264b 100644
--- a/printf/snprntffuns.c
+++ b/printf/snprntffuns.c
@@ -40,9 +40,9 @@ MA 02111-1307, USA. */
#include "gmp-impl.h"
-/* glibc 2.0.x vsnprintf returns size-1 for an overflow, with no indication
- how big the output would have been. It's necessary to re-run to
- determine that size.
+/* glibc 2.0.x vsnprintf returns either -1 or size-1 for an overflow, with
+ no indication how big the output would have been. It's necessary to
+ re-run to determine that size.
"size-1" would mean sucess from a C99 vsnprintf, and the re-run is
unnecessary in this case, but we don't bother to try to detect what sort
@@ -61,7 +61,10 @@ gmp_snprintf_format (struct gmp_snprintf_t *d, const char *fmt, va_list ap)
{
ret = vsnprintf (d->buf, d->size, fmt, ap);
if (ret == -1)
- return ret;
+ {
+ ASSERT (strlen (d->buf) == d->size-1);
+ ret = d->size-1;
+ }
step = MIN (ret, d->size-1);
d->size -= step;
@@ -86,7 +89,7 @@ gmp_snprintf_format (struct gmp_snprintf_t *d, const char *fmt, va_list ap)
ret = vsnprintf (p, alloc, fmt, ap);
(*__gmp_free_func) (p, alloc);
}
- while (ret == alloc-1);
+ while (ret <= alloc-1);
return ret;
}