Sscanf buffer overflow. Bit confused -
Hello, I've managed somehow to make an /pm id msg + /pm on/off so now my problem is the overflow.
pawn Код:
CMD:pm(playerid, params[])
{
CMDUse = 0;
new name[MAX_PLAYER_NAME], id, name2[MAX_PLAYER_NAME], string[64], msg, cmd[3];
if(!sscanf(params, "us[24]", id, msg))
{
if(playerid == id) return SendClientMessage(playerid, COLOR_RED, ""SYNTAX" "COL_WHITE"You can't send yourself private messages!");
GetPlayerName(playerid, name, sizeof(name));
GetPlayerName(id, name2, sizeof(name2));
if(PINFO[playerid][PMToggle] == 1)
{
if(PINFO[id][PMToggle] == 1)
{
if(msg <= 24)
{
format(string, sizeof(string), ""COL_RBLUE"PM > "COL_RED"%s"COL_WHITE"["COL_RED"%d"COL_WHITE"]"COL_RED": "COL_WHITE"%s", name, playerid, msg);
SendClientMessage(id, COLOR_BLUE, string);
format(string, sizeof(string), ""COL_RBLUE"PM >> "COL_RED"%s"COL_WHITE"["COL_RED"%d"COL_WHITE"]"COL_RED": "COL_WHITE"%s", name2, id, msg);
SendClientMessage(playerid, COLOR_BLUE, string);
}
else
{
SendClientMessage(playerid, COLOR_RED, ""SYNTAX" "COL_WHITE"The message is too long [Max "COL_RED"24 "COL_WHITE"characters]");
}
}
else return SendClientMessage(playerid, COLOR_RED, ""SYNTAX" "COL_WHITE"That player has "COL_RED"disabled "COL_WHITE"private messages.");
}
else return SendClientMessage(playerid, COLOR_RED, ""SYNTAX" "COL_WHITE"You have "COL_RED"disabled "COL_WHITE"private messages and you can't send any.");
}
if(!sscanf(params,"s[3]",cmd))
{
if(!strcmp(cmd,"on",true))
{
PINFO[playerid][PMToggle] = 1;
SendClientMessage(playerid, COLOR_GREEN, ""SYNTAX" "COL_WHITE"You have "COL_GREEN"enabled "COL_WHITE"private messages.");
}
if(!strcmp(cmd,"off",true))
{
PINFO[playerid][PMToggle] = 0;
SendClientMessage(playerid, COLOR_GREEN, ""SYNTAX" "COL_WHITE"You have "COL_RED"disabled "COL_WHITE"private messages.");
}
}
return 1;
}
This one works just fine, but I cant return an error message. So when I add the error message, both commands work at the same time and the buffer gets overflowed. Any suggestions?
Re: Sscanf buffer overflow. Bit confused -
When you declare the "msg" variable add a size to it because it's a string.