Raised This Month: $ Target: $400
 0% 

Solved Indexing a string while copying by reference


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-16-2022 , 03:49   Re: Indexing a string inside a native will cause outbounds?
Reply With Quote #1

Quote:
Originally Posted by HamletEagle View Post
The first one can produce an index out of bounds error since you pass the entire array size as 3rd param but the string is smaller because it is sliced.

The second one looks fine.

Are you actually getting an error? What are you really asking?

Yeah i am still getting undefined crashes so its best to avoid the first example.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-16-2022 at 03:51.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 #2

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