summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-02-06 19:03:50 +0000
committerRobin Watts <robin.watts@artifex.com>2013-02-06 19:24:11 +0000
commitc9e73ad96492deeb14851d6af4b8be3f97548784 (patch)
treeb300184c9a061f2fc9ef71b0d189a5b5c72aaffc
parent0399332d547b92c79bfea20982a3a1492f6df272 (diff)
downloadmupdf-c9e73ad96492deeb14851d6af4b8be3f97548784.tar.xz
Fix SEGVs seen on unix caused by the fz_output commit.
It seems that gcc requires arg lists to be 'va_copy'ied, otherwise they can't be reused. This solves problems in the rework of fz_buffer_printf.
-rw-r--r--fitz/stm_buffer.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/fitz/stm_buffer.c b/fitz/stm_buffer.c
index a29f92de..c1405d2f 100644
--- a/fitz/stm_buffer.c
+++ b/fitz/stm_buffer.c
@@ -216,7 +216,7 @@ fz_buffer_printf(fz_context *ctx, fz_buffer *buffer, const char *fmt, ...)
}
int
-fz_buffer_vprintf(fz_context *ctx, fz_buffer *buffer, const char *fmt, va_list args)
+fz_buffer_vprintf(fz_context *ctx, fz_buffer *buffer, const char *fmt, va_list old_args)
{
int len;
@@ -224,12 +224,24 @@ fz_buffer_vprintf(fz_context *ctx, fz_buffer *buffer, const char *fmt, va_list a
{
int slack = buffer->cap - buffer->len;
- len = vsnprintf((char *)buffer->data + buffer->len, slack, fmt, args);
- /* len = number of chars written, not including the terminating
- * NULL, so len+1 > slack means "truncated". MSVC differs here
- * and returns -1 for truncated. */
- if (len > 0 && len+1 <= slack)
- break;
+ if (slack > 0)
+ {
+ va_list args;
+#ifdef _MSC_VER /* Microsoft Visual C */
+ args = old_args;
+#else
+ va_copy(args, old_args);
+#endif
+ len = vsnprintf((char *)buffer->data + buffer->len, slack, fmt, args);
+#ifndef _MSC_VER
+ va_end(args);
+#endif
+ /* len = number of chars written, not including the terminating
+ * NULL, so len+1 > slack means "truncated". MSVC differs here
+ * and returns -1 for truncated. */
+ if (len >= 0 && len+1 <= slack)
+ break;
+ }
/* Grow the buffer and retry */
fz_grow_buffer(ctx, buffer);
}