Commits

jjacky committed 51f32c4

updater: error messages of 1024+ characters are no longer being truncated

Comments (0)

Files changed (2)

  * METHODS *
  ***********/
 
-#define method_failed(name, ...)    do {                        \
-        snprintf (buffer, 1024, __VA_ARGS__);                   \
-        emit_signal ("MethodFailed", "ss", name, buffer);       \
-    } while (0)
+static void
+method_failed (const gchar *name, const gchar *fmt, ...)
+{
+    va_list args;
+    gchar *b = buffer;
+    int len;
+    
+    va_start (args, fmt);
+    len = vsnprintf (b, 1024, fmt, args);
+    va_end (args);
+    if (len >= 1024)
+    {
+        /* this is one long error message... */
+        b = malloc ((size_t) ++len * sizeof (gchar));
+        va_start (args, fmt);
+        vsprintf (b, fmt, args);
+        va_end (args);
+    }
+    emit_signal ("MethodFailed", "ss", name, b);
+    if (b != buffer)
+    {
+        free (b);
+    }
+}
 
 #define method_finished(name)   emit_signal ("MethodFinished", "s", name)
 
 {
     GtkTextMark *mark;
     GtkTextIter iter;
-    gchar buffer[1024];
+    gchar buf[1024], *buffer = buf;
     const char *tag;
     va_list args;
+    int len;
     
     va_start (args, fmt);
-    vsnprintf (buffer, 1024, fmt, args);
+    len = vsnprintf (buffer, 1024, fmt, args);
     va_end (args);
+    if (len >= 1024)
+    {
+        buffer = malloc ((size_t) ++len * sizeof (gchar));
+        va_start (args, fmt);
+        vsprintf (buffer, fmt, args);
+        va_end (args);
+    }
     
     switch (type)
     {
     /* scrolling to the end using gtk_text_view_scroll_to_iter doesn't work;
      * using a mark like so seems to work better... */
     gtk_text_view_scroll_mark_onscreen ( GTK_TEXT_VIEW (updater->text_view), mark);
+    if (buffer != buf)
+    {
+        free (buffer);
+    }
 }
 
 static void
 _show_error (const gchar *msg, const gchar *fmt, ...)
 {
-    gchar buffer[1024], buf[255];
+    gchar *buffer, bufmsg[1024], buf[255];
     va_list args;
+    int len;
     
     snprintf (buf, 255, "<big><b><span color=\"red\">%s</span></b></big>", msg);
     
+    buffer = bufmsg;
     va_start (args, fmt);
-    vsnprintf (buffer, 1024, fmt, args);
+    len = vsnprintf (buffer, 1024, fmt, args);
     va_end (args);
+    if (len >= 1024)
+    {
+        /* this is one long error message... */
+        buffer = malloc ((size_t) ++len * sizeof (gchar));
+        va_start (args, fmt);
+        vsprintf (buffer, fmt, args);
+        va_end (args);
+    }
     
     add_log (LOGTYPE_ERROR, "Error: %s: %s", msg, buffer);
     
     gtk_widget_show (updater->lbl_action);
     gtk_widget_hide (updater->pbar_action);
     gtk_widget_set_sensitive (updater->btn_close, TRUE);
+    if (buffer != bufmsg)
+    {
+        free (buffer);
+    }
 }
 
 static gboolean
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.