PDA

View Full Version : [HELP]sscanf warning: Strings without a length are deprecated, please add a destination size.


Exhibit
19/05/2018, 12:18 PM
I get this warning and then the server crashes. the offline ban command crashes the server.

CMD:oban(playerid,params[])
{
if(PlayerInfo[playerid][pAdmin] < 2) return 0;
{
new otherplayer, filestring[79], string[128], reason[128];
if(sscanf(params, "ss", otherplayer, reason)) return SendClientMessage(playerid, COLOR_GRAY,"Usage: /oban [playername] [reason]");
if(otherplayer == playerid) return SendClientMessage(playerid, COLOR_ERROR, "Error: You cannot offline ban yourself.");
if(PlayerInfo[playerid][pAdmin] < PlayerInfo[otherplayer][pAdmin] && PlayerInfo[playerid][pAdmin] != 6) return SendClientMessage(playerid, COLOR_ERROR, "Error: You cannot offline ban this player.");
format(filestring, sizeof(filestring), "/Users/%s.ini", otherplayer);
if(!fexist(filestring)) return SendClientMessage(playerid, COLOR_ERROR, "Error: Account does not exist.");
else
{
new INI:File = INI_Open(filestring);
INI_SetTag(File,"User Files");
INI_WriteInt(File, "Banned", 1);
INI_WriteString(File, "BannedReason", reason);
INI_WriteString(File, "BannedBy", GetName(playerid));
INI_Close(File);
format(string, sizeof(string), "Admin Log: %s has offline banned player %s.", GetName(playerid), otherplayer);
Admin(COLOR_ADMIN_LOG,string, 1);
SendDC(AUSERLOG, string);
SaveToFile("AdminLogs",string);
}
}
return 1;
}

kovac
19/05/2018, 12:47 PM
new otherplayer[MAX_PLAYER_NAME];
if(sscanf(params, "s[24]s[128]", otherplayer, reason)) return SendClientMessage(playerid, COLOR_GRAY,"Usage: /oban [playername] [reason]");

JasonRiggs
19/05/2018, 12:48 PM
new otherplayer, filestring[79], string[128], reason[128];

it should be like that

new otherplayer[128], filestring[79], string[128], reason[128];

and this line if(sscanf(params, "ss", otherplayer, reason)) return SendClientMessage(playerid, COLOR_GRAY,"Usage: /oban [playername] [reason]");

should be like that

if(sscanf(params, "s[128]s[128]", otherplayer, reason)) return SendClientMessage(playerid, COLOR_GRAY,"Usage: /oban [playername] [reason]");

The point is that you didn't add size for the string..

Logic_
19/05/2018, 02:02 PM
Why would your string and reason array sizes be same? No one would put such a big reason that will occupy all 128 cells, maybe you should use 50 cells instead. And if your reason string is 128 then your string size will be not sufficient for the reason and will require more cells.

Exhibit
19/05/2018, 10:52 PM
It fixed the warning but it still crashes the server when I use the command

Exhibit
27/05/2018, 12:08 AM
Use `u`, not `s`, for player names/IDs.

I am searching for the file of the user(Who is offline) thats why I'm using the string.

It still crashes the server tho

Private200
27/05/2018, 01:10 AM
Use "print"s to see what is being executed and where it actually stops executing (at which point the crash is caused).