Raised This Month: $ Target: $400
 0% 

Solved Indexing a string while copying by reference


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
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 #1

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
Reply



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 11:30.


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