Raised This Month: $ Target: $400
 0% 

replace() buffer not big enough :-?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kmman
Senior Member
Join Date: Sep 2012
Old 09-26-2013 , 17:20   replace() buffer not big enough :-?
Reply With Quote #1

hi there

Error log:
PHP Code:
replace() buffer not big enough (9>=8)
[
AMXXDisplaying debug trace (plugin "swear_replacement.amxx"
[AMXXRun time error 10native error (native "replace"
String_cleaner (line 532
line 515 to 523:
PHP Code:
    for ( len i++ )
    {
        if ( 
str[i] == 'd' )
            
str[i] = 'e'
}
    
len strlen str )
    while ( 
contain str"a" ) != -)
        
replace strlen"a""bc" 
it cannot change "a" to "bc" because it has 2 characters
it only can change to a 1 character value.
how to fix it?
kmman is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-26-2013 , 18:49   replace() buffer not big enough :-?
Reply With Quote #2

Make "str" bigger.
__________________
Black Rose is offline
kmman
Senior Member
Join Date: Sep 2012
Old 09-26-2013 , 19:44   Re: replace() buffer not big enough :-?
Reply With Quote #3

Quote:
Make "str" bigger.
As you may know:
PHP Code:
//replace usage:
replace text[], len, const what[], const with[] ) 

//and here in this plugin:
replace str  len,  "a"  "bc"     
you mean I should make Text bigger?!

Last edited by kmman; 09-26-2013 at 19:47.
kmman is offline
Old 09-26-2013, 23:59
11922911
This message has been deleted by 11922911.
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-27-2013 , 00:32   replace() buffer not big enough :-?
Reply With Quote #4

replace(str, charsmax(str), ...
__________________
Black Rose is offline
kmman
Senior Member
Join Date: Sep 2012
Old 09-27-2013 , 01:45   Re: replace() buffer not big enough :-?
Reply With Quote #5

Quote:
Originally Posted by Black Rose View Post
replace(str, charsmax(str), ...
The string length increases after replacement , eg:

input: aaa
replace>>>
output: bcbcbc

Will charsmax(str) fix this too?
kmman is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 09-27-2013 , 02:12   Re: replace() buffer not big enough :-?
Reply With Quote #6

Show more code, at least the whole function.
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 09-27-2013 , 02:46   Re: replace() buffer not big enough :-?
Reply With Quote #7

Replace your while loop with replace_all

When using replace(_all), you need to make sure that your array is large enough to accomidate the new length. A good rule to follow is that if you are replacing a single character with 2 characters, then your new array should be at least twice as large as the original. Same is true if you are replacing a single character with 3 characters, the array should be 3 times as large.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
kmman
Senior Member
Join Date: Sep 2012
Old 09-27-2013 , 05:00   Re: replace() buffer not big enough :-?
Reply With Quote #8

Quote:
Originally Posted by YamiKaitou View Post
Replace your while loop with replace_all

When using replace(_all), you need to make sure that your array is large enough to accomidate the new length. A good rule to follow is that if you are replacing a single character with 2 characters, then your new array should be at least twice as large as the original. Same is true if you are replacing a single character with 3 characters, the array should be 3 times as large.

you mean to change replace to replace_all ?
PHP Code:
    len strlen str )
    while ( 
contain str"a" ) != -)
        
replace_all strlen"a""bc" 
kmman is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-27-2013 , 05:07   replace() buffer not big enough :-?
Reply With Quote #9

charsmax solves his problem because he is passing current length as maxlength which makes it impossible to increase string length even if there's room in the actual string variable.
__________________
Black Rose is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 09-27-2013 , 06:01   Re: replace() buffer not big enough :-?
Reply With Quote #10

Quote:
Originally Posted by kmman View Post
you mean to change replace to replace_all ?
PHP Code:
    len strlen str )
    while ( 
contain str"a" ) != -)
        
replace_all strlen"a""bc" 
No, I mean delete the while loop completely and just use replace_all
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou 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 04:47.


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