#1

Hi,

I use zcmd include and sometimes there is player which write long command like: /asdmasdkajsdkjsajdkjqwkejqwkejqwejk, this gives

Код:
[debug] Run time error 4: "Array index out of bounds"
[debug]  Attempted to read/write array element at index 32 in array of size 32
[debug] AMX backtrace:
in public OnPlayerCommandText
Reply
#2

This isn't a ZCMD-related issue.
Reply
#3

Yeah, in the include, look where [32] is and raise it up to [145]
Reply
#4

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
Yeah, in the include, look where [32] is and raise it up to [145]
No need, because this isn't a ZCMD-related issue.
Reply
#5

Yes it's because MAX_FUNC_NAME is 32, so if player write longer command it gives that error, i need don't letplayer write that long command
Reply
#6

Quote:
Originally Posted by MerryDeer
Посмотреть сообщение
Yes it's because MAX_FUNC_NAME is 32, so if player write longer command it gives that error, i need don't letplayer write that long command
No! Even try it in a blank script with just ZCMD and the basic needs added, use /asdmasdkajsdkjsajdkjqwkejqwkejqwejk and you'll see that you don't get that error.
Reply
#7

So then to what it's related? i just use zcmd
Reply
#8

Whether or not it's a ZCMD-related issue is arguable since it doesn't check the size of cmdtext before using its indices in a smaller array. It's definitely an underlying PAWN issue:
PHP код:
CMD:thiscommandshouldbearound33charse(playerid) {
    return 
true

gives a warning: warning 200: symbol "cmd_thiscommandshouldbearound33" is truncated to 31 characters. Because functions in the SA-MP's compiler for PAWN can't exceed 31 characters and if you look at the ZCMD source code, it basically creates a new function for each command that you write:
PHP код:
#define COMMAND:%1(%2)          \
            
forward cmd_%1(%2); \
            public 
cmd_%1(%2
And such big commands IG do give you the array out of bounds for cmdtext in OnPlayerCommandText:
Код:
[debug] Run time error 4: "Array index out of bounds"
[debug]  Accessing element at index 32 past array upper bound 31
[debug] AMX backtrace:
[debug] #0 00000260 in public OnPlayerCommandText (playerid=0, cmdtext[]=@00000324 "/eiejgoergoierjgioerjgiojerjgierjoogieorjgoejrg") at F:\cnr\OSG-CNR\pawno\include\zcmd.inc:94
The include itself has a lot of calls referring to the indices of funcname which is declared with a size of MAX_FUNC_NAME (set to 32):
PHP код:
while (cmdtext[++pos] > ' '
{
    
funcname[pos-1] = tolower(cmdtext[pos]); 

When cmdtext[++pos] exceeds 33, it tries to access funcname[32] which is out of its bounds and thus resulting in the error.

TL; DR: ZCMD is accessing indices of funcname[] out of its bounds resulting in the error. Raising MAX_FUNC_NAME to anything past 32 is not going to work as functions in PAWN can't exceed 31 characters.

EDIT: Also refer to SickAttack's post below:
Quote:
Originally Posted by SickAttack
Посмотреть сообщение
By loading CrashDetect (it doesn't come out by default), it's only logical for the error to appear (by following the include's code). But that's why OnPlayerCommandReceived exists (though, it could be added in the code directly which the author didn't do):
pawn Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    new pos;
    while(cmdtext[pos] != ' ' && cmdtext[pos] != EOS)
    {
        pos ++;
    }

    if(pos > 28)
    {
        return SendClientMessage(playerid, -1, "Command is invalid."), 0;
    }
    return 1;
}
Reply
#9

By loading CrashDetect (it doesn't come out by default), it's only logical for the error to appear (by following the include's code). But that's why OnPlayerCommandReceived exists (though, it could be added in the code directly which the author didn't do):
pawn Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    new pos;
    while(cmdtext[pos] != ' ' && cmdtext[pos] != EOS)
    {
        pos ++;
    }

    if(pos > 28)
    {
        return SendClientMessage(playerid, -1, "Command is invalid."), 0;
    }
    return 1;
}

CMD:aaaaaaaaaaaaaaaaaaaaaaaaaaa(playerid)
{
    SendClientMessage(playerid, -1, "This is the longest a command can get!");
    return 1;
}
Reply
#10

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
By loading CrashDetect (it doesn't come out by default), it's only logical for the error to appear (by following the include's code).
True. I should've said that crashdetect was being loaded for the tests.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)