summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsabetts <sabetts>2001-10-02 05:11:41 +0000
committersabetts <sabetts>2001-10-02 05:11:41 +0000
commitec05e9d4a92fd0ef59d13b875ca61213c0f49906 (patch)
treef72f327507272d536828dea85380bb0cd16eb829 /src
parent7124de1cd87cd2694f9b9751c9800db6b183b6a7 (diff)
downloadratpoison-ec05e9d4a92fd0ef59d13b875ca61213c0f49906.zip
(marked_message_printf): Handle a return value from
vsnprintf of -1 properly.
Diffstat (limited to 'src')
-rw-r--r--src/bar.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/bar.c b/src/bar.c
index 3189d5b..a329d47 100644
--- a/src/bar.c
+++ b/src/bar.c
@@ -132,7 +132,20 @@ marked_message_printf (int mark_start, int mark_end, char *fmt, ...)
buffer = (char *)xmalloc (size);
nchars = vsnprintf (buffer, size, fmt, ap);
- if (nchars >= size)
+
+ /* From the GNU Libc manual: In versions of the GNU C library prior
+ to 2.1 the return value is the number of characters stored, not
+ including the terminating null; unless there was not enough space
+ in S to store the result in which case `-1' is returned. */
+ if (nchars == -1)
+ {
+ do
+ {
+ size *= 2;
+ buffer = (char *)xrealloc (buffer, size);
+ } while (vsnprintf (buffer, size, fmt, ap) == -1);
+ }
+ else if (nchars >= size)
{
buffer = (char *)xrealloc (buffer, nchars + 1);
vsnprintf (buffer, nchars + 1, fmt, ap);