From: havoc Date: Tue, 23 Jan 2007 16:58:57 +0000 (+0000) Subject: changed Cmd_StuffCmds_f to combine the entire set of commandline arguments into one... X-Git-Tag: xonotic-v0.1.0preview~3666 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=16538d1c3734ca88fe949234e4dc7d37d3e584fe;p=xonotic%2Fdarkplaces.git changed Cmd_StuffCmds_f to combine the entire set of commandline arguments into one string before calling Cbuf_InsertText, this fixes the reverse order execution bug (where +deathmatch 7 +map dpdm2 would execute deathmatch 7 AFTER starting the map, which was useless until a restart command was issued) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6742 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cmd.c b/cmd.c index a59a46f6..7a4c5c17 100644 --- 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); }