sscanf string length
#1

I have this command, when I remove the overflow it works perfectly although can go over string limit of 'MAX_PLAYER_NAME' - 24.
This crashes the server, so i'm just starting to add these overflow things in to all my commands although this particular command just keep showing the scp...
PHP код:
forward OnAccountUnsuspended(adminID);
public 
OnAccountUnsuspended(adminID) {
    new 
rows;
    
cache_get_row_count(rows);
    if(
rows) {
    } else return 
SendError(playerid"Couldn't find the selected account.");
    return 
1;
}
COMMAND:unsuspend(playeridparams[]) {
    if(!
PlayerInfo[playerid][aAdmin] && !PlayerInfo[playerid][aHelper]) return SendError(playeridCANT_USE_CMD);
    new 
iPlayer[MAX_PLAYER_NAME];
    if(
sscanf(params"s[" #MAX_PLAYER_NAME "]", iPlayer)) return SCP(playerid, "< Full_Name >");
    
if(!IsPlayerConnected(GetPlayerId(iPlayer))) {
        new 
iQuery[159]; mysql_format(PipelineiQuerysizeof(iQuery), "SELECT `ID`, `AccountID`, `CharName` FROM `pInfo` WHERE `CharName` = '%e' LIMIT 1"iPlayer);
        
mysql_tquery(PipelineiQuery"OnAccountUnsuspended""d"playerid);
    } else return 
SendError(playeridCANT_FIND_PLAYER);
    return 
1;

Also am I using an outdated sscanf?
my version: https://pastebin.com/jew8sFh2
Reply
#2

Why don't you just use 24 instead of this disaster
Код:
"s[" #MAX_PLAYER_NAME "]"
Reply
#3

PHP код:
"s[" #MAX_PLAYER_NAME "]" 
is fine as long as MAX_PLAYER_NAME don't have any brackets involved like:
PHP код:
#define MAX_PLAYER_NAME (24) 
Reply
#4

You don't need to use sscanf if the only input is a string. Simply use strlen to check if the length is between 1 - 24. You can also check for forbidden characters, although I assume that one trusts his own hired admins.

Also don't call your variables "iQuery" and "iPlayer" when they in fact contain text. Unless the "i" actually stands for input or index. But I reckon most people (like me) will read the "i" as "integer" which is confusing as hell in situations like this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)