AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Which is it for getting the position of formatex? (https://forums.alliedmods.net/showthread.php?t=29781)

Geesu 06-12-2006 14:16

Which is it for getting the position of formatex?
 
Which is correct?

new szMsg[512], pos = 0;
Code:
        pos += formatex( szMsg[pos], 512-pos, "^n%L: %d^n%L: %d", id, "CURRENT_HEALTH", get_user_health( iTargetID ), id, "WORD_ARMOR", get_user_armor( iTargetID ) );

or

Code:
        pos += formatex( szMsg[pos], 511-pos, "^n%L: %d^n%L: %d", id, "CURRENT_HEALTH", get_user_health( iTargetID ), id, "WORD_ARMOR", get_user_armor( iTargetID ) );

I changed 512-pos to 511-pos, which should it be?

Thanks,
Josh

Greenberet 06-12-2006 14:40

511
xor start with pos = 1

jtp10181 06-12-2006 15:11

if you use 512 you could overflow your var and overwrite other memory and cause a fun crash. It really has nothing to do with "getting" the position. That arg is setting the max length to copy into the var. So if you start at pos 0 (which is correct) and the var is len 512 you should copy a max of 511 (511 - 0).

Geesu 06-13-2006 12:17

thanks guys, you'd think I'd know this being a 4th year comp. sci. eng. :P


All times are GMT -4. The time now is 08:08.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.