[gnac/devel] Used g_vasprintf instead of g_vsnprintf



commit 4060880bbc922f2e5021a454d5a26022d0b3c3d2
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date:   Mon Jan 23 18:05:15 2012 +0000

    Used g_vasprintf instead of g_vsnprintf

 libgnac/libgnac-debug.c |   39 ++++++++++++++++++++++++++-------------
 1 files changed, 26 insertions(+), 13 deletions(-)
---
diff --git a/libgnac/libgnac-debug.c b/libgnac/libgnac-debug.c
index 524e845..486143e 100644
--- a/libgnac/libgnac-debug.c
+++ b/libgnac/libgnac-debug.c
@@ -28,9 +28,10 @@
 #include "config.h"
 #endif
 
+#include <glib/gprintf.h>
+
 #include "libgnac-debug.h"
 
-#define BUFFER_SIZE 1024
 
 gboolean LIBGNAC_DEBUG;
 gboolean LIBGNAC_VERBOSE;
@@ -45,13 +46,16 @@ libgnac_debug_real(const gchar *func,
   if (!LIBGNAC_DEBUG) return;
 
 	va_list args;
-	char buffer[BUFFER_SIZE];
+	gchar *buffer;
 
 	va_start(args, format);
-	g_vsnprintf(buffer, BUFFER_SIZE, format, args);
+	gint ret = g_vasprintf(&buffer, format, args);
 	va_end(args);
 
-  g_printerr("[DEBUG] %s:%d: %s\n", file, line, buffer);
+  if (ret != -1) {
+    g_printerr("[DEBUG] %s:%d: %s\n", file, line, buffer);
+    g_free(buffer);
+  }
 }
 
 
@@ -63,13 +67,16 @@ libgnac_critical_real(const gchar *func,
                       ...)
 {
 	va_list args;
-	char buffer[BUFFER_SIZE];
+	gchar *buffer;
 
 	va_start(args, format);
-	g_vsnprintf(buffer, BUFFER_SIZE, format, args);
+	gint ret = g_vasprintf(&buffer, format, args);
 	va_end(args);
 
-  g_printerr("[CRITICAL] %s:%d: %s\n", file, line, buffer);
+  if (ret != -1) {
+    g_printerr("[CRITICAL] %s:%d: %s\n", file, line, buffer);
+    g_free(buffer);
+  }
 }
 
 
@@ -81,13 +88,16 @@ libgnac_warning_real(const gchar *func,
                      ...)
 {
 	va_list args;
-	char buffer[BUFFER_SIZE];
+	gchar *buffer;
 
 	va_start(args, format);
-	g_vsnprintf(buffer, BUFFER_SIZE, format, args);
+	gint ret = g_vasprintf(&buffer, format, args);
 	va_end(args);
 
-  g_printerr("[WARNING] %s:%d: %s\n", file, line, buffer);
+  if (ret != -1) {
+    g_printerr("[WARNING] %s:%d: %s\n", file, line, buffer);
+    g_free(buffer);
+  }
 }
 
 
@@ -97,11 +107,14 @@ libgnac_info(const gchar *format, ...)
   if (!LIBGNAC_VERBOSE) return;
 
 	va_list args;
-	char buffer[BUFFER_SIZE];
+	gchar *buffer;
 
 	va_start(args, format);
-	g_vsnprintf(buffer, BUFFER_SIZE, format, args);
+	gint ret = g_vasprintf(&buffer, format, args);
 	va_end(args);
 
-  g_print("[INFO] %s\n", buffer);
+  if (ret != -1) {
+    g_print("[INFO] %s\n", buffer);
+    g_free(buffer);
+  }
 }



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