util/log: Fix log messages over 1024 characters.
authorEmma Anholt <emma@anholt.net>
Thu, 20 Apr 2023 23:12:57 +0000 (16:12 -0700)
committerMarge Bot <emma+marge@anholt.net>
Mon, 24 Apr 2023 21:56:05 +0000 (21:56 +0000)
The first attempt at the sprintf would have consumed part of va, so if
we're going to recurse on overflow to try again in a new allocation then
we have to do our work on a copy.

This was a common failure mode for MESA_GLSL=source, where it would just print:

  Mesa: info: GLSL source for fragment shader 1:
  Mesa: info: (null)

Fixes: 7a18a1712a0a ("util/log: improve logger_file newline handling")
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22618>

src/util/log.c

index 6b5b3ae..45ecdd8 100644 (file)
@@ -148,7 +148,7 @@ logger_vasnprintf(char *buf,
                   enum mesa_log_level level,
                   const char *tag,
                   const char *format,
-                  va_list va)
+                  va_list in_va)
 {
    struct {
       char *cur;
@@ -160,6 +160,9 @@ logger_vasnprintf(char *buf,
       .rem = size,
    };
 
+   va_list va;
+   va_copy(va, in_va);
+
 #define APPEND(state, func, ...)                                     \
    do {                                                              \
       int ret = func(state.cur, state.rem, __VA_ARGS__);             \
@@ -195,7 +198,7 @@ logger_vasnprintf(char *buf,
       void *alloc = malloc(state.total + 1);
       if (alloc) {
          buf = logger_vasnprintf(alloc, state.total + 1, affixes, level, tag,
-               format, va);
+               format, in_va);
          assert(buf == alloc);
       } else {
          /* pretty-truncate the message */
@@ -203,6 +206,8 @@ logger_vasnprintf(char *buf,
       }
    }
 
+   va_end(va);
+
    return buf;
 }