AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Out of Bounds formatex (https://forums.alliedmods.net/showthread.php?t=101019)

Bad_Bud 08-20-2009 00:03

Out of Bounds formatex
 
I'm making a stupid mistake, but I can't figure out what it is.

Code:

Run time error 4: index out of bounds
For the line below with the formatex

PHP Code:

new WriteTitle[33][25]

...

new 
ItemsNames[1][33]

formatex(ItemsNames[0],32,"Letter: %s",WriteTitle[id]) 

I don't understand how it can be out of bounds. I'm taking a string of size 24 and adding 8 letters to it, then putting it in a max 32 size string. It shouldn't be possible to go over.

Exolent[jNr] 08-20-2009 00:09

Re: Out of Bounds formatex
 
PHP Code:

new WriteTitle[33][25]

...

new 
ItemsNames[33]

formatex(ItemsNames,32,"Letter: %s",WriteTitle[id]) 


Bad_Bud 08-20-2009 00:24

Re: Out of Bounds formatex
 
The function I'm passing it to requires ItemsNames to be two-dimensional -- sometimes I pass in more than one name (NumItems).

PHP Code:

AddItems(id,NumItems,Items[],ItemsNames[][],ItemsModels[][])
{
...


And here's another excerpt from another function right before it calls AddItems (this does not go out of bounds):

PHP Code:

new ItemsNames[1][33]
...
formatex(ItemsNames[0],32,"%s",Temp


ConnorMcLeod 08-20-2009 00:38

Re: Out of Bounds formatex
 
Try new ItemsNames[2][33], not logical but your error is weird.

Bad_Bud 08-20-2009 00:44

Re: Out of Bounds formatex
 
Hmm, it still went out. I'm also only putting one letter into WriteTitle in an attempt to make it as small as possible.

PHP Code:

public SQL_NewLetter(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
        return 
set_fail_state("Could not connect to SQL database.")
    else if(
FailState == TQUERY_QUERY_FAILED)
        return 
set_fail_state("Query failed.")
    
    if(
Errcode)
        return 
log_amx("Error on query: %s",Error)
    
    new 
Items[2]
    new 
ItemsNames[1][33]
    new 
ItemsModels[1][65]
    
    
Items[0]=SQL_GetInsertId(Query)
    
Items[1]=1
    
    formatex
(ItemsNames[0],32,"Letter: %s",WriteTitle[Data[0]])
    
ItemsModels[0]="models/Roleplay/Backpack.mdl"
    
    
AddItems(Data[0],1,Items,ItemsNames,ItemsModels)
        
    return 
PLUGIN_CONTINUE


The whole function. WriteTitle is global.

Heh, even made it [1][3300] and it still went out of bounds.

Edit: I think it must be the that WriteTitle is somehow going out of bounds because of the value that's in Data[0], but that should be the player's index...

PHP Code:

if(!WritingLetter[id])
 {
     
client_print(id,print_chat,"*End of letter.")
     new 
Data[1]
    
Data[0]=id
    
    
new Query[256]
    
format(Query,255,"INSERT INTO items (ItemName,ItemDescription,ItemString,ItemCommand) VALUES ('Letter: %s','Letter: %s','%s','Item_Letter')",WriteTitle[id],WriteDescription[id],WriteLocation[id])
    
SQL_ThreadQuery(SQL_Tuple,"SQL_NewLetter",Query)


Final edit: F*** :( I forgot to pass in the data array ;/

Thanks for your help guys.

Exolent[jNr] 08-20-2009 01:06

Re: Out of Bounds formatex
 
Quote:

Originally Posted by Bad_Bud (Post 906247)
I'm making a stupid mistake, but I can't figure out what it is.

Code:

Run time error 4: index out of bounds
For the line below with the formatex

PHP Code:

new WriteTitle[33][25]

...

new 
ItemsNames[1][33]

formatex(ItemsNames[0],32,"Letter: %s",WriteTitle[id]) 

I don't understand how it can be out of bounds. I'm taking a string of size 24 and adding 8 letters to it, then putting it in a max 32 size string. It shouldn't be possible to go over.

Quote:

Originally Posted by Bad_Bud (Post 906263)
The function I'm passing it to requires ItemsNames to be two-dimensional -- sometimes I pass in more than one name (NumItems).

PHP Code:

AddItems(id,NumItems,Items[],ItemsNames[][],ItemsModels[][])
{
...


And here's another excerpt from another function right before it calls AddItems (this does not go out of bounds):

PHP Code:

new ItemsNames[1][33]
...
formatex(ItemsNames[0],32,"%s",Temp


If the 2nd doesn't have the error, then it must be from this line:
PHP Code:

formatex(ItemsNames[0],32,"Letter: %s",WriteTitle[id]) 

Where "id" is out of the 33 array bounds.

ConnorMcLeod 08-20-2009 01:14

Re: Out of Bounds formatex
 
Quote:

Originally Posted by Exolent[jNr] (Post 906282)
If the 2nd doesn't have the error, then it must be from this line:
PHP Code:

formatex(ItemsNames[0],32,"Letter: %s",WriteTitle[id]) 

Where "id" is out of the 33 array bounds.

That would make more sense.

Bad_Bud 08-20-2009 04:28

Re: Out of Bounds formatex
 
Quote:

Originally Posted by Bad_Bud (Post 906273)
Final edit: F*** :( I forgot to pass in the data array ;/

Data was out of bounds... lol


All times are GMT -4. The time now is 15:09.

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