Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
updated: [master] [7c415f2] (enter): use GString instead of hand-made memory (re)allocation.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Andrew Borodin  
View profile  
 More options Nov 9 2012, 1:12 am
From: "Andrew Borodin" <aboro...@vmail.ru>
Date: Fri, 9 Nov 2012 07:12:01 +0100 (CET)
Local: Fri, Nov 9 2012 1:12 am
Subject: updated: [master] [7c415f2] (enter): use GString instead of hand-made memory (re)allocation.
The following commit has been merged in the master branch:
commit 7c415f2ec5a725d3c6f3aa114acdfd2868797aef
Author: Andrew Borodin <aboro...@vmail.ru>
Date:   Fri Nov 2 13:44:47 2012 +0400

    (enter): use GString instead of hand-made memory (re)allocation.

    Signed-off-by: Andrew Borodin <aboro...@vmail.ru>

diff --git a/src/filemanager/command.c b/src/filemanager/command.c
index bfe286d..d98b772 100644
--- a/src/filemanager/command.c
+++ b/src/filemanager/command.c
@@ -258,8 +258,8 @@ enter (WInput * lc_cmdline)
     }
     else
     {
-        char *command, *s;
-        size_t i, j, cmd_len;
+        GString *command;
+        size_t i;

         if (!vfs_current_is_local ())
         {
@@ -275,30 +275,25 @@ enter (WInput * lc_cmdline)
             return MSG_NOT_HANDLED;
         }
 #endif
-        cmd_len = strlen (cmd);
-        command = g_malloc (cmd_len + 1);
-        command[0] = 0;
-        for (i = j = 0; i < cmd_len; i++)
+        command = g_string_sized_new (32);
+
+        for (i = 0; cmd[i] != '\0'; i++)
         {
-            if (cmd[i] == '%')
-            {
-                i++;
-                s = expand_format (NULL, cmd[i], TRUE);
-                command = g_realloc (command, j + strlen (s) + cmd_len - i + 1);
-                strcpy (command + j, s);
-                g_free (s);
-                j = strlen (command);
-            }
+            if (cmd[i] != '%')
+                g_string_append_c (command, cmd[i]);
             else
             {
-                command[j] = cmd[i];
-                j++;
+                char *s;
+
+                s = expand_format (NULL, cmd[++i], TRUE);
+                g_string_append (command, s);
+                g_free (s);
             }
-            command[j] = 0;
         }
+
         input_clean (lc_cmdline);
-        shell_execute (command, 0);
-        g_free (command);
+        shell_execute (command->str, 0);
+        g_string_free (command, TRUE);

 #ifdef ENABLE_SUBSHELL
         if ((quit & SUBSHELL_EXIT) != 0)

--
Midnight Commander Development


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »