summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorbrl <brl>2007-08-14 20:20:57 +0000
committerbrl <brl>2007-08-14 20:20:57 +0000
commitdaa5550f2e424a88ba6de7602fab405808a2ef23 (patch)
tree5d6fb3f051af6c1938091e64270a8163be1f0528 /src/main.c
parent1bea7fa97bbdb1ceeb2696b8982a1e025ef751f4 (diff)
downloadratpoison-daa5550f2e424a88ba6de7602fab405808a2ef23.zip
src/main.c (xvsprintf): limit memory allocation to 200K when vsnprintf return -1.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 7c7b468..933decb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -126,15 +126,24 @@ xvsprintf (char *fmt, va_list ap)
return buffer;
else if (nchars > -1)
size = nchars + 1;
- else
+ /* c99 says -1 is an error other than truncation,
+ * which thus will not go away with a larger buffer.
+ * To support older system but not making errors fatal
+ * (ratpoison will abort when trying to get too much memory otherwise),
+ * try to increase a bit but not too much: */
+ else if (size < MAX_LEGACY_SNPRINTF_SIZE)
size *= 2;
+ else
+ {
+ free(buffer);
+ break;
+ }
/* Resize the buffer and try again. */
buffer = (char *)xrealloc (buffer, size);
}
- /* Never gets here. */
- return NULL;
+ return xstrdup("<FAILURE>");
}
/* Return a new string based on fmt. */