about summary refs log tree commit diff
path: root/argp
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-11-10 08:15:19 +0000
committerUlrich Drepper <drepper@redhat.com>1999-11-10 08:15:19 +0000
commitb9d3d9f726a79f0c1091e80cfb21e27eaed130c0 (patch)
treeb4bffa1c2f8ab000bc31b745dfbfab91f6410c4d /argp
parent2864e767053317538feafa815046fff89e5a16be (diff)
downloadglibc-b9d3d9f726a79f0c1091e80cfb21e27eaed130c0.tar.gz
glibc-b9d3d9f726a79f0c1091e80cfb21e27eaed130c0.tar.xz
glibc-b9d3d9f726a79f0c1091e80cfb21e27eaed130c0.zip
Update.
1999-11-10  Andreas Jaeger  <aj@suse.de>

	* string/strsignal.c (strsignal): Correct check for snprintf
	return value.
	* argp/argp-fmtstream.c (__argp_fmtstream_printf): Likewise.

	* misc/efgcvt_r.c (APPEND): Correct check for too small buffer
	according to changed snprintf return value.
	Reported by Lawrence K. Chen <lchen@opentext.com>.

	* misc/tst-efgcvt.c (special): Add tests for a too small buffer
	for ecvt_r and fcvt_r.
Diffstat (limited to 'argp')
-rw-r--r--argp/argp-fmtstream.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/argp/argp-fmtstream.c b/argp/argp-fmtstream.c
index d563c31b8e..ae547b0acb 100644
--- a/argp/argp-fmtstream.c
+++ b/argp/argp-fmtstream.c
@@ -1,5 +1,5 @@
 /* Word-wrapping and line-truncating streams
-   Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <miles@gnu.ai.mit.edu>.
 
@@ -362,6 +362,7 @@ ssize_t
 __argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...)
 {
   int out;
+  size_t avail;
   size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */
 
   do
@@ -370,13 +371,15 @@ __argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...)
 
       if (! __argp_fmtstream_ensure (fs, size_guess))
 	return -1;
-      size_guess += size_guess;
 
       va_start (args, fmt);
-      out = __vsnprintf (fs->p, fs->end - fs->p, fmt, args);
+      avail = fs->end - fs->p;
+      out = __vsnprintf (fs->p, avail, fmt, args);
       va_end (args);
+      if (out >= avail)
+	size_guess = out + 1;
     }
-  while (out == -1);
+  while (out >= avail);
 
   fs->p += out;