]> granicus.if.org Git - strace/blobdiff - vsprintf.c
tests: add a test for -yy option
[strace] / vsprintf.c
index 71bdf8c921852ec46f81dfc45452c4d8591af49c..0125e7205a3199f70bd5e3946da6618847e38f12 100644 (file)
  */
 
 #include "defs.h"
+
+#if USE_CUSTOM_PRINTF
+
 #include <stdarg.h>
 #include <limits.h>
 
-#ifdef USE_CUSTOM_PRINTF
+#ifndef HAVE_FPUTS_UNLOCKED
+# define fputs_unlocked fputs
+#endif
 
 #define noinline_for_stack /*nothing*/
 #define likely(expr)       (expr)
@@ -758,8 +763,8 @@ int kernel_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 
 int strace_vfprintf(FILE *fp, const char *fmt, va_list args)
 {
-       static char *buf;
-       static unsigned buflen;
+       static char *buf = NULL;
+       static unsigned buflen = 0;
 
        int r;
        va_list a1;
@@ -772,6 +777,8 @@ int strace_vfprintf(FILE *fp, const char *fmt, va_list args)
                buflen = len + 256;
                free(buf);
                buf = malloc(buflen);
+               if (!buf)
+                       die_out_of_memory();
                /*len =*/ kernel_vsnprintf(buf, buflen, fmt, args);
        }