View Single Post
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-16-2022 , 06:19   Re: Indexing a string inside a native will cause outbounds?
Reply With Quote #6

Quote:
Originally Posted by Natsheh View Post
Yeah i am still getting undefined crashes so its best to avoid the first example.
It makes perfect sense that you are getting errors using the first code snippet.

PHP Code:
new szName[32];
get_user_name(idszName[10], charsmax(szName)); 
szName has 32 cells but in get_user_name you pass szName[10] which will pass cells 10, 11, 12, ...., 31(a buffer with only 22 cells). Your 3rd argument, the buffer size, is charsmax(szName) which will return 31. 31 > 22 so the native will attempt to write up to 31 characters in a buffer that can only hold 22.

This is the same as doing
PHP Code:
new buf[22]
for(
int i 032i++)
{
    
buf[i] = i

__________________

Last edited by HamletEagle; 01-16-2022 at 06:20.
HamletEagle is offline