Raised This Month: $ Target: $400
 0% 

replace() buffer not big enough


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OnePL
BANNED
Join Date: May 2012
Location: GB
Old 08-02-2014 , 08:25   replace() buffer not big enough
Reply With Quote #1

I have a error:
Code:
L 08/02/2014 - 13:13:02: replace() buffer not big enough (64>=63)
L 08/02/2014 - 13:13:02: [AMXX] Run time error 10: native error (native "replace")
L 08/02/2014 - 13:13:02: [AMXX]    [0] string.inc::replace_all (line 879)
L 08/02/2014 - 13:13:02: [AMXX]    [1] Untitled.sma::SQL_PrepareString (line 236)
L 08/02/2014 - 13:13:02: [AMXX]    [2] Untitled.sma::client_infochanged (line 125)
code looks like this

PHP Code:
new nazwa_gracza[33][128];
public 
client_putinserver(id) {    
    if(
is_user_hltv(id) || is_user_bot(id)) return;

    
get_user_name(idnazwa_gracza[id], 63);
    
SQL_PrepareString(nazwa_gracza[id], nazwa_gracza[id]);
}

public 
client_infochanged(id) {
    if(!
is_user_connected(id)) return 0;

    new 
name[128]; get_user_info(id"name"name127);
    if(
equal(namenazwa_gracza[id])) return 0;

    
SQL_PrepareString(nazwa_gracza[id], name);
    
formatex(nazwa_gracza[id], 127name);
    return 
0;
}

stock SQL_PrepareString(szQuery[], szOutPut[]) {
    
copy(szOutPut127szQuery);
    
replace_all(szOutPut127"'""\'");
    
replace_all(szOutPut127"`""\`");
    
replace_all(szOutPut127"\\""\\\\");
    
replace_all(szOutPut127"\0""\\0");
    
replace_all(szOutPut127"\n""\\n");
    
replace_all(szOutPut127"\r""\\r");
    
replace_all(szOutPut127"^0""\0");
    
replace_all(szOutPut127"^n""\n");
    
replace_all(szOutPut127"^r""\r");
    
replace_all(szOutPut127"^"", "\^"");
    
replace_all(szOutPut127"<""\<");
    
replace_all(szOutPut127">""\>");
    
replace_all(szOutPut127"^x1a""\Z");

line 236:
PHP Code:
replace_all(szOutPut127"\\""\\\\"); 
line 125 (in the client_infochanged):
PHP Code:
SQL_PrepareString(nazwa_gracza[id], name); 
what causes this error?

Last edited by OnePL; 08-02-2014 at 08:27.
OnePL is offline
Send a message via ICQ to OnePL Send a message via AIM to OnePL Send a message via Yahoo to OnePL Send a message via Skype™ to OnePL
GordonFreeman (RU)
Veteran Member
Join Date: Jan 2010
Location: Uzbekistan
Old 08-02-2014 , 08:50   Re: replace() buffer not big enough
Reply With Quote #2

Try use this stock:
Code:
stock replace_all2(string[], len, const what[], const with[])
{
	new pos = 0;
	
	if ((pos = contain(string, what)) == -1)
	{
		return 0;
	}
	
	new total = 0;
	new with_len = strlen(with);
	new diff = strlen(what) - with_len;
	new total_len = strlen(string);
	new temp_pos = 0;
	
	while (total_len + with_len < len && replace(string[pos], len - pos, what, with) != 0)
	{
		total++;

		/* jump to position after replacement */
		pos += with_len;
		
		/* update cached length of string */
		total_len -= diff;
		
		/* will the next call be operating on the last character? */
		if (pos >= total_len)
		{
			break;
		}
		
		/* find the next position from our offset */
		temp_pos = contain(string[pos], what);
		
		/* if it's invalid, we're done */
		if (temp_pos == -1)
		{
			break;
		}
		
		/* otherwise, reposition and update counters */
		pos += temp_pos;
	}
	
	return total;
}
__________________
The functional way is the right way
GordonFreeman (RU) is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 08-02-2014 , 11:08   Re: replace() buffer not big enough
Reply With Quote #3

The error is caused by replacing eg. 2 characters with 4 characters, as you have done and the string array cannot fit it in.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
OnePL
BANNED
Join Date: May 2012
Location: GB
Old 08-02-2014 , 13:15   Re: replace() buffer not big enough
Reply With Quote #4

how to fix it?
some characters need to change with more characters eg \\ -> \\\\ to save data to sql was correct

Last edited by OnePL; 08-02-2014 at 13:15.
OnePL is offline
Send a message via ICQ to OnePL Send a message via AIM to OnePL Send a message via Yahoo to OnePL Send a message via Skype™ to OnePL
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 08-02-2014 , 18:02   Re: replace() buffer not big enough
Reply With Quote #5

Make the buffer bigger
__________________
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 21:43.


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