]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
changed Cmd_StuffCmds_f to combine the entire set of commandline arguments into one...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 23 Jan 2007 16:58:57 +0000 (16:58 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 23 Jan 2007 16:58:57 +0000 (16:58 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6742 d7cf8633-e32d-0410-b094-e92efae38249

cmd.c

diff --git a/cmd.c b/cmd.c
index a59a46f6189e86fe3ed91c5ee282f31100ec107a..7a4c5c17ee7a4ef94510b5bb93e04816876b0c7e 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -216,7 +216,7 @@ qboolean host_stuffcmdsrun = false;
 void Cmd_StuffCmds_f (void)
 {
        int             i, j, l;
-       // this is per command, and bounds checked (no buffer overflows)
+       // this is for all commandline options combined (and is bounds checked)
        char    build[MAX_INPUTLINE];
 
        if (Cmd_Argc () != 1)
@@ -230,11 +230,12 @@ void Cmd_StuffCmds_f (void)
                return;
 
        host_stuffcmdsrun = true;
+       build[0] = 0;
+       l = 0;
        for (i = 0;i < com_argc;i++)
        {
-               if (com_argv[i] && com_argv[i][0] == '+' && (com_argv[i][1] < '0' || com_argv[i][1] > '9'))
+               if (com_argv[i] && com_argv[i][0] == '+' && (com_argv[i][1] < '0' || com_argv[i][1] > '9') && l + strlen(com_argv[i]) - 1 <= sizeof(build) - 1)
                {
-                       l = 0;
                        j = 1;
                        while (com_argv[i][j])
                                build[l++] = com_argv[i][j++];
@@ -245,20 +246,24 @@ void Cmd_StuffCmds_f (void)
                                        continue;
                                if ((com_argv[i][0] == '+' || com_argv[i][0] == '-') && (com_argv[i][1] < '0' || com_argv[i][1] > '9'))
                                        break;
-                               if (l + strlen(com_argv[i]) + 5 > sizeof(build))
+                               if (l + strlen(com_argv[i]) + 4 > sizeof(build) - 1)
                                        break;
                                build[l++] = ' ';
-                               build[l++] = '\"';
+                               if (strchr(com_argv[i], ' '))
+                                       build[l++] = '\"';
                                for (j = 0;com_argv[i][j];j++)
                                        build[l++] = com_argv[i][j];
-                               build[l++] = '\"';
+                               if (strchr(com_argv[i], ' '))
+                                       build[l++] = '\"';
                        }
                        build[l++] = '\n';
-                       build[l++] = 0;
-                       Cbuf_InsertText (build);
                        i--;
                }
        }
+       // now terminate the combined string and prepend it to the command buffer
+       // we already reserved space for the terminator
+       build[l++] = 0;
+       Cbuf_InsertText (build);
 }