aboutsummaryrefslogtreecommitdiffstats
path: root/man3/printf.3
diff options
context:
space:
mode:
Diffstat (limited to 'man3/printf.3')
-rw-r--r--man3/printf.315
1 files changed, 11 insertions, 4 deletions
diff --git a/man3/printf.3 b/man3/printf.3
index bbb2f5b879..09f8e78b68 100644
--- a/man3/printf.3
+++ b/man3/printf.3
@@ -1025,6 +1025,9 @@ one might obtain "Sonntag, 3. Juli, 10:02".
.PP
To allocate a sufficiently large string and print into it
(code correct for both glibc 2.0 and glibc 2.1):
+.PP
+If truncation occurs in glibc versions prior to 2.0.6, this is treated as an
+error instead of being handled gracefully.
.nf
#include <stdio.h>
@@ -1050,17 +1053,21 @@ make_message(const char *fmt, ...)
n = vsnprintf(p, size, fmt, ap);
va_end(ap);
+ /* Check error code */
+
+ if (n < 0)
+ return NULL;
+
/* If that worked, return the string. */
- if (n > \-1 && n < size)
+ if (n < size)
return p;
/* Else try again with more space. */
- if (n > \-1) /* glibc 2.1 */
+ else
size = n+1; /* precisely what is needed */
- else /* glibc 2.0 */
- size *= 2; /* twice the old size */
+
if ((np = realloc (p, size)) == NULL) {
free(p);