]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Rephrase VM_altstr_prepare to no longer annoy Coverity.
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 5 Mar 2015 12:15:43 +0000 (12:15 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 5 Mar 2015 12:15:43 +0000 (12:15 +0000)
(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

index 9776b9ac28aadf33283d134fee07db3f0176ab5f..332fe75bee6929f8688c805219521997ece8f9c9 100644 (file)
@@ -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 );
 }