[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnulib] vasnprintf.c: patch for inadequate snprintf on HPUX 10.20
From: |
Jim Meyering |
Subject: |
[Bug-gnulib] vasnprintf.c: patch for inadequate snprintf on HPUX 10.20 |
Date: |
Sun, 19 Oct 2003 22:58:11 +0200 |
Hi Bruno,
This started because people reported that `who' of coreutils-5.0.91
would fail with an apparent out of memory error on HPUX systems.
It came down to the fact that asprintf would sometimes return -1
(with errno == EINVAL) under some circumstances.
That in turn was because vasnprintf didn't handle the case in which
snprintf doesn't honor %n, and in addition returns -1 when formatting
the supplied arguments would require more than the specified size.
Here's the proposed patch:
2003-10-19 Jim Meyering <address@hidden>
* vasnprintf.c (vasnprintf): Work around losing snprintf on
e.g. HPUX 10.20.
Index: vasnprintf.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/vasnprintf.c,v
retrieving revision 1.7
diff -u -p -u -p -r1.7 vasnprintf.c
--- vasnprintf.c 13 Sep 2003 22:14:47 -0000 1.7
+++ vasnprintf.c 19 Oct 2003 19:04:35 -0000
@@ -707,6 +707,22 @@ vasnprintf (char *resultbuf, size_t *len
p[1] = '\0';
continue;
}
+ else if (retcount < 0)
+ {
+ /* The system's snprintf is sorely deficient:
+ it doesn't recognize the `%n' directive, and it
+ returns -1 (rather than the length that would
+ have been required) when the buffer is too small.
+ This is the case at with least HPUX 10.20.
+ Double the memory allocation. */
+ size_t n = allocated;
+ if (n < 2 * allocated)
+ {
+ n = 2 * allocated;
+ ENSURE_ALLOCATION (n);
+ continue;
+ }
+ }
count = retcount;
}
#endif
- [Bug-gnulib] vasnprintf.c: patch for inadequate snprintf on HPUX 10.20,
Jim Meyering <=