[babl] resolve ambiguous calling of real_babl_log with va_args



commit e439557f9e89e159a9f8dd8043e89e843ac60d82
Author: Paul Fredrickson <p_fredrickson hotmail com>
Date:   Mon Mar 17 20:17:43 2014 -0700

    resolve ambiguous calling of real_babl_log with va_args
    
    In babl-internal.h there are two different ways of calling real_babl_log.
    One matches the macro definitions of babl_log which expects an arbitrary
    number of parameters, and the other is to pass a va_list used to access
    those parameters. The latter case can be found in the function definition
    of babl_log when an appropriate macro definition is not selected.
    
    It may be that some platforms implement varargs in such a way that
    passing a va_list pointing to the params of another call stack is the
    same as passing those parameters directly, but that definitely isn't
    the case on mac OS X, where this results in corrupted strings when
    calling babl_log or babl_fatal.
    
    The solution here is to create a varargs-enabled version of real_babl_log
    that accepts a va_list, and have all calls eventually call into that.
    
    (This may not be seen under normal configurations. This was discovered
    while trying to build with a hand-crafted config.h in Xcode.)

 babl/babl-internal.h |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)
---
diff --git a/babl/babl-internal.h b/babl/babl-internal.h
index 38b59b1..cc05660 100644
--- a/babl/babl-internal.h
+++ b/babl/babl-internal.h
@@ -112,14 +112,13 @@ int      babl_type_is_symmetric         (const Babl     *babl);
 int babl_backtrack (void);
 
 static inline void
-real_babl_log (const char *file,
-               int         line,
-               const char *function,
-               const char *fmt, ...)
+real_babl_log_va(const char *file,
+                 int         line,
+                 const char *function,
+                 const char *fmt,
+                 va_list     varg)
 {
   Babl *extender = babl_extender();
-  va_list  varg;
-
 
   if (extender != babl_extension_quiet_log())
     {
@@ -129,15 +128,26 @@ real_babl_log (const char *file,
       fprintf (stdout, "%s:%i %s()\n\t", file, line, function);
     }
 
-  va_start (varg, fmt);
   vfprintf (stdout, fmt, varg);
-  va_end (varg);
 
   fprintf (stdout, "\n");
   fflush (NULL);
   return;
 }
 
+static inline void
+real_babl_log (const char *file,
+               int         line,
+               const char *function,
+               const char *fmt, ...)
+{
+  va_list  varg;
+
+  va_start (varg, fmt);
+  real_babl_log_va(file, line, function, fmt, varg);
+  va_end (varg);
+}
+
 /* Provide a string identifying the current function, non-concatenatable */
 #ifndef G_STRFUNC
 #if defined (__GNUC__)
@@ -180,7 +190,7 @@ babl_log (const char *format, ...)
 {
   va_list args;
   va_start (args, format);
-  real_babl_log (__FILE__, __LINE__, G_STRFUNC, format, args);
+  real_babl_log_va (__FILE__, __LINE__, G_STRFUNC, format, args);
   va_end (args);
 }
 static inline void
@@ -188,7 +198,7 @@ babl_fatal (const char *format, ...)
 {
   va_list args;
   va_start (args, format);
-  real_babl_log (__FILE__, __LINE__, G_STRFUNC, format, args);
+  real_babl_log_va (__FILE__, __LINE__, G_STRFUNC, format, args);
   va_end (args);
   babl_die();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]