From cad099a6ef73f318b6c5655072e46141e3524636 Mon Sep 17 00:00:00 2001 From: divverent Date: Thu, 5 Mar 2015 12:15:43 +0000 Subject: [PATCH] Rephrase VM_altstr_prepare to no longer annoy Coverity. (I think the previous code had no bug, but was hard to follow) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12201 d7cf8633-e32d-0410-b094-e92efae38249 --- prvm_cmds.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/prvm_cmds.c b/prvm_cmds.c index 9776b9ac..332fe75b 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -4425,23 +4425,26 @@ string altstr_prepare(string) */ void VM_altstr_prepare(prvm_prog_t *prog) { - char *out; const char *instr, *in; int size; char outstr[VM_STRINGTEMP_LENGTH]; + int outpos; VM_SAFEPARMCOUNT( 1, VM_altstr_prepare ); instr = PRVM_G_STRING( OFS_PARM0 ); - for( out = outstr, in = instr, size = sizeof(outstr) - 1 ; size && *in ; size--, in++, out++ ) - if( *in == '\'' && size > 1) { - *out++ = '\\'; - *out = '\''; - size--; - } else - *out = *in; - *out = 0; + for (in = instr, outpos = 0; *in && outpos < sizeof(outstr) - 1; ++in) + { + if (*in == '\'' && outpos < sizeof(outstr) - 2) + { + out[outpos++] = '\\'; + out[outpos++] = '\''; + } + else + out[outpos++] = *in; + } + out[outpos++] = 0; PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, outstr ); } -- 2.39.2