Prefer dynamically allocated buffers to fixed-size ones, use the same
authorwwp <wwp@free.fr>
Fri, 13 Jan 2017 08:19:41 +0000 (09:19 +0100)
committerwwp <wwp@free.fr>
Fri, 13 Jan 2017 08:19:41 +0000 (09:19 +0100)
src/compose.c
src/crash.c
src/plugins/pgpcore/pgp_viewer.c
src/plugins/vcalendar/libical/libical/icalproperty.c
src/textview.c

index 0c147906d814ddc95274df56dc4e0f9592d591c9..bdb14b40a7b056da15040808683726d58bf5478c 100644 (file)
@@ -9478,7 +9478,7 @@ static gboolean compose_get_ext_editor_cmd_valid()
 
 static gint compose_exec_ext_editor_real(const gchar *file, GdkNativeWindow socket_wid)
 {
-       gchar buf[1024];
+       gchar *buf;
        gchar *p, *s;
        gchar **cmdline;
        pid_t pid;
@@ -9503,22 +9503,22 @@ static gint compose_exec_ext_editor_real(const gchar *file, GdkNativeWindow sock
                        s = strstr(p, "%w");
                        s[1] = 'u';
                        if (strstr(p, "%s") < s)
-                               g_snprintf(buf, sizeof(buf), p, file, socket_wid);
+                               buf = g_strdup_printf(p, file, socket_wid);
                        else
-                               g_snprintf(buf, sizeof(buf), p, socket_wid, file);
+                               buf = g_strdup_printf(p, socket_wid, file);
                        g_free(p);
                } else {
-                       g_snprintf(buf, sizeof(buf),
-                                  prefs_common_get_ext_editor_cmd(), file);
+                       buf = g_strdup_printf(prefs_common_get_ext_editor_cmd(), file);
                }
        } else {
                if (prefs_common_get_ext_editor_cmd())
                        g_warning("External editor command-line is invalid: '%s'",
                                  prefs_common_get_ext_editor_cmd());
-               g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
+               buf = g_strdup_printf(DEFAULT_EDITOR_CMD, file);
        }
 
-       cmdline = strsplit_with_quote(buf, " ", 1024);
+       cmdline = strsplit_with_quote(buf, " ", 0);
+       g_free(buf);
        execvp(cmdline[0], cmdline);
 
        perror("execvp");
index a48401271f679793d40401fb8274f083d02ddbab..8df5d9fb088d3e3f2e64da5adb97646cc5c443fe 100644 (file)
@@ -369,7 +369,7 @@ static void crash_debug(unsigned long crash_pid,
                        perror("dup");
                close(choutput[0]);
                if (-1 == execvp("gdb", argp)) 
-                       g_print("error execvp\n");
+                       perror("execvp");
        } else {
                char buf[100];
                int r;
@@ -547,6 +547,7 @@ static void crash_handler(int sig)
                if (setuid(getuid()) != 0 )
                        perror("setuid");
                execvp(argv0, args);
+               perror("execvp");
        } else {
                waitpid(pid, NULL, 0);
                crash_cleanup_exit();
index d1b0448a56d5ecb323744c33f61c9c182d57b969..01427609d9c6c4f97695ef72f404f09d8491a0ef 100644 (file)
@@ -208,6 +208,7 @@ static void pgpview_show_mime_part(TextView *textview, MimeInfo *partinfo)
                                gchar **argv;
                                argv = strsplit_with_quote(cmd, " ", 0);
                                res = execvp(argv[0], argv);
+                               perror("execvp");
                                exit(255);
                        } else {
                                int status = 0;
index 855e24be3a5287ff5990a5a8e7ef1771dd057f17..6faaf8add75fdae10de67e30907e4cb1c1c0bc9c 100644 (file)
@@ -44,8 +44,8 @@
 #include <errno.h>
 #include <stdio.h> /* for printf */
 #include <stdarg.h> /* for va_list, va_start, etc. */
-                                               
-#define TMP_BUF_SIZE 1024
+
+#define BUF_SIZE 1024
 
 /* Private routines for icalproperty */
 void icalvalue_set_parent(icalvalue* value,
@@ -175,7 +175,7 @@ icalproperty_new_clone(icalproperty* prop)
 icalproperty* icalproperty_new_from_string(char* str)
 {
 
-    size_t buf_size = 1024;
+    size_t buf_size = BUF_SIZE;
     char* buf;
     char* buf_ptr;  
     icalproperty *prop;
@@ -279,7 +279,7 @@ icalproperty_as_ical_string (icalproperty* prop)
        the caller forgetting to free it */
 
     const char* property_name = 0; 
-    size_t buf_size = 1024;
+    size_t buf_size = BUF_SIZE;
     char* buf;
     char* buf_ptr;
     icalvalue* value;
@@ -381,9 +381,10 @@ icalproperty_as_ical_string (icalproperty* prop)
        }
 
        if (kind_string == 0 ) {
-           char temp[TMP_BUF_SIZE];
-           snprintf(temp, TMP_BUF_SIZE,"Got a parameter of unknown kind in %s property",property_name);
+           char *temp;
+           temp = g_strdup_printf(temp, "Got a parameter of unknown kind in %s property", property_name);
            icalerror_warn(temp);
+           g_free(temp);
            continue;
        }
 
index b73071f071f83d5bafbba0d16ec2077627339740..7372a1c21ceed9fea7b0d93ce0904892a7173f35 100644 (file)
@@ -1141,6 +1141,7 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                        close(pfd[0]);
                        rc = dup(pfd[1]);
                        rc = execvp(argv[0], argv);
+                       perror("execvp");
                        close(pfd[1]);
                        g_print(_("The command to view attachment "
                                "as text failed:\n"