]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
make str2chr return 0 when used on an index outside the string (before, it didn't...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 28 Jul 2007 15:50:49 +0000 (15:50 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 28 Jul 2007 15:50:49 +0000 (15:50 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7498 d7cf8633-e32d-0410-b094-e92efae38249

prvm_cmds.c

index 6b5e8d6f55a433a9dd874ccd3a92f6e9d21f707d..f5021549bdbad5be21b8874255ed843580f82af0 100644 (file)
@@ -3802,9 +3802,10 @@ void VM_str2chr (void)
        const char *s;
        VM_SAFEPARMCOUNT(2, VM_str2chr);
        s = PRVM_G_STRING(OFS_PARM0);
-       if((unsigned)PRVM_G_FLOAT(OFS_PARM1) > strlen(s))
-               return;
-       PRVM_G_FLOAT(OFS_RETURN) = (unsigned char)s[(int)PRVM_G_FLOAT(OFS_PARM1)];
+       if((unsigned)PRVM_G_FLOAT(OFS_PARM1) < strlen(s))
+               PRVM_G_FLOAT(OFS_RETURN) = (unsigned char)s[(unsigned)PRVM_G_FLOAT(OFS_PARM1)];
+       else
+               PRVM_G_FLOAT(OFS_RETURN) = 0;
 }
 
 //#223 string(float c, ...) chr2str (FTE_STRINGS)