Some more g_strdup_printf() eliminated



Hello, Pavel!

P.S. g_strcompress() cannot be used to interpret C literals in regular expressions entered by the user, e.g. \r and \0x0D.  It replace '\.' with '.' ;-(

-- 
Regards,
Andrew V. Samoilov.
edit/ChangeLog:

	* editcmd.c (pipe_mail):  Eliminate g_strdup_printf().
	(edit_complete_word_cmd): Fix possible buffer overflow.

src/ChangeLog:

	* hotlist.c (add_new_group_input): Clean up.

	* wtools.c (do_create_message): Eliminate g_strdup_printf().
	(bg_message): Ditto.

vfs/ChangeLog:
	* direntry.c (vfs_s_resolve_symlink): Eliminate g_strdup_printf().
	(vfs_s_fullpath): Ditto.

--- edit/editcmd.c
+++ edit/editcmd.c
@@ -2528,7 +2528,7 @@ static void pipe_mail (WEdit *edit, char
     to = name_quote (to, 0);
     subject = name_quote (subject, 0);
     cc = name_quote (cc, 0);
-    s = g_strdup_printf ("mail -s %s -c %s %s", subject, cc, to);
+    s = g_strconcat ("mail -s ", subject, *cc ? " -c " : "" , cc, " ",  to, NULL);
     g_free (to);
     g_free (subject);
     g_free (cc);
@@ -2792,7 +2789,7 @@ edit_complete_word_cmd (WEdit *edit)
     int word_len = 0, i, num_compl = 0, max_len;
     long word_start = 0;
     char *bufpos;
-    char match_expr[MAX_REPL_LEN];
+    char *match_expr;
     struct selection compl[MAX_WORD_COMPLETIONS];	/* completions */
 
     /* don't want to disturb another search */
@@ -2809,9 +2806,7 @@ edit_complete_word_cmd (WEdit *edit)
     /* prepare match expression */
     bufpos = &edit->buffers1[word_start >> S_EDIT_BUF_SIZE]
 	[word_start & M_EDIT_BUF_SIZE];
-    strncpy (match_expr, bufpos, word_len);
-    match_expr[word_len] = '\0';
-    strcat (match_expr, "[a-zA-Z_0-9]+");
+    match_expr = g_strdup_printf ("%.*s[a-zA-Z_0-9]+", word_len, bufpos);
 
     /* init search: backward, regexp, whole word, case sensitive */
     edit_set_search_parameters (0, 1, 1, 1, 1);
@@ -2842,6 +2837,7 @@ edit_complete_word_cmd (WEdit *edit)
 	}
     }
 
+    g_free (match_expr);
     /* release memory before return */
     for (i = 0; i < num_compl; i++)
 	g_free (compl[i].text);
--- src/hotlist.c~	Tue Nov 11 14:22:01 2003
+++ src/hotlist.c	Fri Nov 21 16:16:46 2003
@@ -973,7 +973,7 @@ static int add_new_group_input (char *he
     
     Quick_input.widgets = quick_widgets;
     if ((ret = quick_dialog (&Quick_input)) != B_CANCEL){
-	*result = *(quick_widgets [3].str_result);
+	*result = my_str;
 	return ret;
     } else
 	return 0;
--- src/wtools.c
+++ src/wtools.c
@@ -200,7 +200,7 @@ do_create_message (int flags, const char
     Dlg_head *d;
 
     /* Add empty lines before and after the message */
-    p = g_strdup_printf ("\n%s\n", text);
+    p = g_strconcat ("\n", text, "\n", NULL);
     query_dialog (title, p, flags, 0);
     d = last_query_dlg;
     init_dlg (d);
@@ -253,7 +253,7 @@ fg_message (int flags, const char *title
 static void
 bg_message (int dummy, int *flags, char *title, const char *text)
 {
-    title = g_strdup_printf ("%s %s", _("Background process:"), title);
+    title = g_strconcat (_("Background process:"), " ", title, NULL);
     fg_message (*flags, title, text);
     g_free (title);
 }
--- vfs/direntry.c
+++ vfs/direntry.c
@@ -217,7 +217,7 @@ vfs_s_resolve_symlink (struct vfs_class 
     /* make full path from relative */
     if (*linkname != PATH_SEP) {
 	char *fullpath = vfs_s_fullpath (me, entry->dir);
-	fullname = g_strdup_printf ("%s/%s", fullpath, linkname);
+	fullname = g_strconcat (fullpath, "/", linkname, NULL);
 	linkname = fullname;
 	g_free (fullpath);
     }
@@ -522,7 +522,7 @@ vfs_s_fullpath (struct vfs_class *me, st
 	    ino = ino->ent->dir;
 	    if (ino == ino->super->root)
 		break;
-	    newpath = g_strdup_printf ("%s/%s", ino->ent->name, path);
+	    newpath = g_strconcat (ino->ent->name, "/", path, NULL);
 	    g_free (path);
 	    path = newpath;
 	}


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