]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
redesigned much of PF_VarString to clean it up (shorter, faster, etc)
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 8 Jul 2003 09:51:12 +0000 (09:51 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 8 Jul 2003 09:51:12 +0000 (09:51 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3185 d7cf8633-e32d-0410-b094-e92efae38249

pr_cmds.c

index 8acdec77240eba646f95210407c7c3b2cbbb56e1..b432657bd800c37fe2671cba0539dd7038b846b7 100644 (file)
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -41,26 +41,21 @@ char pr_varstring_temp[MAX_VARSTRING];
 */
 
 
-char *PF_VarString (int        first)
+char *PF_VarString (int first)
 {
-       int i, j, end;
-       char *s;
+       int i;
+       const char *s;
+       char *out, *outend;
 
-       end = 0;
-       for (i = first;i < pr_argc;i++)
+       out = pr_varstring_temp;
+       outend = pr_varstring_temp + sizeof(pr_varstring_temp) - 1;
+       for (i = first;i < pr_argc && out < outend;i++)
        {
-               // LordHavoc: FIXME: this is just a strlcat inlined
                s = G_STRING((OFS_PARM0+i*3));
-               j = strlen(s);
-               if (j > MAX_VARSTRING - 1 - end)
-                       j = MAX_VARSTRING - 1 - end;
-               if (j > 0)
-               {
-                       memcpy(pr_varstring_temp + end, s, j);
-                       end += j;
-               }
+               while (out < outend && *s)
+                       *out++ = *s++;
        }
-       pr_varstring_temp[end] = 0;
+       *out++ = 0;
        return pr_varstring_temp;
 }