Raised This Month: $ Target: $400
 0% 

[Solved]Index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
#8 SickneSS
BANNED
Join Date: Sep 2008
Location: Here
Old 07-13-2010 , 17:50   [Solved]Index out of bounds
Reply With Quote #1

Code:
L 07/13/2010 - 18:27:05: [AMXX] Run time error 4: index out of bounds 
L 07/13/2010 - 18:27:05: [AMXX] [0] Mix_Maker.sma::cmdSayRestart (line 930)
PHP Code:
public cmdSayRestart(id,level,cid) {
    
    if(!
cmd_access(id,level,cid,1))
        return 
PLUGIN_HANDLED
    
    
new said[192]
    
read_args(said,191)
    
remove_quotes(said)
    
    if(!
strlen(said) || said[0] == ' ')
        return 
PLUGIN_HANDLED
        
    
new name[32]
    
get_user_name(id,name,31)
    
    new 
Restart[11]
    new 
Tmp[11]
    
strbreak(said,Restart,10,Tmp,10)
    
    new 
Value str_to_num(Tmp)

    new const 
Restrts[][] = 
    { 
        
"/restart","!restart",".restart",
        
"/rr","!rr",".rr",
        
"/r","!r",".r" 
    
}
    
    for(new 
0;<= sizeof (Restrts);i++)
    {
        if(
equali(Restart,Restrts[i]))
        {
            if(!
is_str_num(Tmp) || Value 60)
                
Value 1
                    
            
if(!Tmp[0])
                
set_pcvar_num(pRestart,1)
            else
                
set_pcvar_num(pRestart,Value)
                
            
ChatColor(0,"%s !yADMIN %s : Restarteo la ronda",szPrefix,name)
            return 
PLUGIN_HANDLED
        
}
    }
    return 
PLUGIN_CONTINUE

#8 SickneSS is offline
Send a message via MSN to #8 SickneSS Send a message via Skype™ to #8 SickneSS
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-13-2010 , 17:59   Re: Index out of bounds
Reply With Quote #2

You need to learn that it's much much easier if we know what line is the line referenced in the error.

The error is cause by the <= in the for loop. Must be only <.
__________________

Last edited by fysiks; 07-13-2010 at 20:18. Reason: Fixed my typo to correct solution.
fysiks is offline
#8 SickneSS
BANNED
Join Date: Sep 2008
Location: Here
Old 07-13-2010 , 17:59   Re: Index out of bounds
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
You need to learn that it's much much easier if we know what line is the line referenced in the error.
PHP Code:
        if(equali(Restart,Restrts[i])) 
I trying searching the same error in others plugins,but I can't find the solution.
#8 SickneSS is offline
Send a message via MSN to #8 SickneSS Send a message via Skype™ to #8 SickneSS
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-13-2010 , 18:01   Re: Index out of bounds
Reply With Quote #4

Found the error, read above.
__________________
fysiks is offline
#8 SickneSS
BANNED
Join Date: Sep 2008
Location: Here
Old 07-13-2010 , 18:06   Re: Index out of bounds
Reply With Quote #5

If I change that the command doesn't works

Last edited by #8 SickneSS; 07-13-2010 at 18:14.
#8 SickneSS is offline
Send a message via MSN to #8 SickneSS Send a message via Skype™ to #8 SickneSS
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-13-2010 , 18:24   Re: Index out of bounds
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
You need to learn that it's much much easier if we know what line is the line referenced in the error.

The error is cause by the <= in the for loop. Must be only =
<
__________________
Bugsy is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 07-13-2010 , 18:33   Re: Index out of bounds
Reply With Quote #7

I think fysiks wanted to say "<"

PHP Code:
for(new 0;sizeof (Restrts);i++) 
You have to remember that the last number of the array size is null... so if you use "<=" you use Restrts[9] and you should use at Restrt[8] (9 is null).
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Alucard^ is offline
Send a message via Skype™ to Alucard^
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-13-2010 , 18:38   Re: Index out of bounds
Reply With Quote #8

Quote:
Originally Posted by Alucard^ View Post
I think fysiks wanted to say "<"

PHP Code:
for(new 0;sizeof (Restrts);i++) 
You have to remember that the last number of the array size is null... so if you use "<=" you use Restrts[9] and you should use at Restrt[8] (9 is null).
An array is sized with the number specified but elements are accessed with indexes starting at 0. The last element being null is really only with null terminated strings. Index out of bounds is telling you that your trying to reference memory that doesn't exist. If you size the array at 8 then the last element is 7.
__________________

Last edited by Bugsy; 07-13-2010 at 18:41.
Bugsy is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 07-13-2010 , 18:41   Re: Index out of bounds
Reply With Quote #9

Emm yes i know that elements are accesed with indexes starting at 0, but i didn't understand this:

Quote:
The last element being null is really only with null terminated strings
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Alucard^ is offline
Send a message via Skype™ to Alucard^
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-13-2010 , 18:52   Re: Index out of bounds
Reply With Quote #10

An array can hold any values in every index. When an array holds a string, the last element is reserved for a null char to signify end of string
__________________
Bugsy 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 07:13.


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