Raised This Month: $ Target: $400
 0% 

Which is it for getting the position of formatex?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Geesu
Veteran Member
Join Date: Mar 2004
Location: Cincinnati, OH
Old 06-12-2006 , 14:16   Which is it for getting the position of formatex?
Reply With Quote #1

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
__________________
Need war3ft help? DO NOT PM ME... Check the forums
Geesu is offline
Send a message via AIM to Geesu Send a message via MSN to Geesu
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 06-12-2006 , 14:40  
Reply With Quote #2

511
xor start with pos = 1
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 06-12-2006 , 15:11  
Reply With Quote #3

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).
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
Geesu
Veteran Member
Join Date: Mar 2004
Location: Cincinnati, OH
Old 06-13-2006 , 12:17  
Reply With Quote #4

thanks guys, you'd think I'd know this being a 4th year comp. sci. eng.
__________________
Need war3ft help? DO NOT PM ME... Check the forums
Geesu is offline
Send a message via AIM to Geesu Send a message via MSN to Geesu
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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