Skip to content

Commit b122b5b

Browse files
committed
xrGame: Adapt sscanf_s for ISO C++ (dangerous)
This removes the size checks on Windows too.
1 parent 2cbf6c0 commit b122b5b

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

src/xrGame/account_manager_console.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ void CCC_CreateGameSpyAccount::Execute(LPCSTR args)
2424
string256 tmp_email;
2525
string256 tmp_password;
2626

27-
sscanf_s(args, "%s %s %s %s", tmp_nick, sizeof(tmp_nick), tmp_unick, sizeof(tmp_unick), tmp_email,
28-
sizeof(tmp_email), tmp_password, sizeof(tmp_password));
27+
sscanf(args, "%s %s %s %s", tmp_nick, tmp_unick, tmp_email,tmp_password);
2928

3029
VERIFY(MainMenu() && MainMenu()->GetGS());
3130
CGameSpy_GP* tmp_gp = MainMenu()->GetGS()->GetGameSpyGP();
@@ -54,7 +53,7 @@ void CCC_GapySpyListProfiles::Execute(LPCSTR args)
5453
string256 tmp_email;
5554
string256 tmp_password;
5655

57-
sscanf_s(args, "%s %s", tmp_email, sizeof(tmp_email), tmp_password, sizeof(tmp_password));
56+
sscanf(args, "%s %s", tmp_email, tmp_password);
5857

5958
VERIFY(MainMenu() && MainMenu()->GetGS());
6059
CGameSpy_GP* tmp_gp = MainMenu()->GetGS()->GetGameSpyGP();
@@ -76,8 +75,7 @@ void CCC_GameSpyLogin::Execute(LPCSTR args)
7675
string256 tmp_nick;
7776
string256 tmp_password;
7877

79-
sscanf_s(
80-
args, "%s %s %s", tmp_email, sizeof(tmp_email), tmp_nick, sizeof(tmp_nick), tmp_password, sizeof(tmp_password));
78+
sscanf(args, "%s %s %s", tmp_email, tmp_nick, tmp_password);
8179

8280
VERIFY(MainMenu() && MainMenu()->GetGS());
8381
CGameSpy_GP* tmp_gp = MainMenu()->GetGS()->GetGameSpyGP();
@@ -97,7 +95,7 @@ void CCC_GameSpyLogout::Execute(LPCSTR args)
9795

9896
static char const* print_time(time_t const& src_time, string64& dest_time)
9997
{
100-
tm* tmp_tm = _localtime64(&src_time);
98+
tm* tmp_tm = localtime(&src_time);
10199
xr_sprintf(dest_time, sizeof(dest_time), "%02d.%02d.%d_%02d:%02d:%02d", tmp_tm->tm_mday, tmp_tm->tm_mon + 1,
102100
tmp_tm->tm_year + 1900, tmp_tm->tm_hour, tmp_tm->tm_min, tmp_tm->tm_sec);
103101
return dest_time;
@@ -153,7 +151,7 @@ void CCC_GameSpySuggestUNicks::Execute(LPCSTR args)
153151
{
154152
VERIFY(MainMenu() && MainMenu()->GetGS());
155153
string256 tmp_unick;
156-
sscanf_s(args, "%s", tmp_unick, sizeof(tmp_unick));
154+
sscanf(args, "%s", tmp_unick);
157155
gamespy_gp::account_manager* tmp_amngr = MainMenu()->GetAccountMngr();
158156
VERIFY(tmp_amngr);
159157
tmp_amngr->suggest_unique_nicks(tmp_unick, gamespy_gp::suggest_nicks_cb());
@@ -163,7 +161,7 @@ void CCC_GameSpyRegisterUniqueNick::Execute(LPCSTR args)
163161
{
164162
VERIFY(MainMenu() && MainMenu()->GetGS());
165163
gamespy_gp::login_manager::unique_nick_t tmp_unick;
166-
sscanf_s(args, "%s", tmp_unick, sizeof(tmp_unick));
164+
sscanf(args, "%s", tmp_unick);
167165
gamespy_gp::login_manager* tmp_lmngr = MainMenu()->GetLoginMngr();
168166
VERIFY(tmp_lmngr);
169167
tmp_lmngr->set_unique_nick(tmp_unick, gamespy_gp::login_operation_cb());
@@ -195,7 +193,7 @@ void CCC_GameSpyProfile::Execute(LPCSTR args)
195193
}
196194

197195
string256 tmp_command;
198-
sscanf_s(args, "%s", tmp_command, sizeof(tmp_command));
196+
sscanf(args, "%s", tmp_command);
199197
if (!xr_strcmp(tmp_command, "load"))
200198
{
201199
/*tmp_prof_store->set_current_profile(
@@ -214,7 +212,7 @@ void CCC_GameSpyProfile::Execute(LPCSTR args)
214212
char const* tmp_reward_id_str = args + xr_strlen(tmp_command);
215213
int tmp_award_id = 0;
216214

217-
if (!sscanf_s(tmp_reward_id_str, "%u", &tmp_award_id))
215+
if (!sscanf(tmp_reward_id_str, "%u", &tmp_award_id))
218216
{
219217
Msg("! Bad award id");
220218
return;
@@ -229,7 +227,7 @@ void CCC_GameSpyProfile::Execute(LPCSTR args)
229227
char const* tmp_scores_str = args + xr_strlen(tmp_command);
230228
unsigned int score_id = 0;
231229
int score_value = 0;
232-
if (sscanf_s(tmp_scores_str, "%u %u", &score_id, &score_value) != 2)
230+
if (sscanf(tmp_scores_str, "%u %u", &score_id, &score_value) != 2)
233231
{
234232
Msg("! Not enough parameters");
235233
return;

src/xrGame/console_commands_mp.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ class CCC_KickPlayerByID : public IConsole_Command
416416
else
417417
{
418418
u32 tmp_client_id;
419-
if (sscanf_s(args, "%u", &tmp_client_id) != 1)
419+
if (sscanf(args, "%u", &tmp_client_id) != 1)
420420
{
421421
Msg("! ERROR: bad command parameters.");
422422
Msg("Kick player. Format: \"sv_kick_id <player session id | \'%s\'>\". To receive list of players ids "
@@ -508,7 +508,7 @@ class CCC_MakeScreenshot : public IConsole_Command
508508
else
509509
{
510510
u32 tmp_client_id;
511-
if (sscanf_s(args_, "%u", &tmp_client_id) != 1)
511+
if (sscanf(args_, "%u", &tmp_client_id) != 1)
512512
{
513513
Msg("! ERROR: bad command parameters.");
514514
Msg("Make screenshot. Format: \"make_screenshot <player session id | \'%s\'> <ban_time_in_sec>\". To "
@@ -556,7 +556,7 @@ class CCC_MakeConfigDump : public IConsole_Command
556556
else
557557
{
558558
u32 tmp_client_id;
559-
if (sscanf_s(args_, "%u", &tmp_client_id) != 1)
559+
if (sscanf(args_, "%u", &tmp_client_id) != 1)
560560
{
561561
Msg("! ERROR: bad command parameters.");
562562
Msg("Make screenshot. Format: \"make_config_dump <player session id | \'%s\'> <ban_time_in_sec>\". To "
@@ -615,7 +615,7 @@ class DemoPlayControlArgParser
615615
string32 param_name;
616616
param_name[0] = 0;
617617

618-
sscanf_s(args_string, "%16s %32s", action_name, sizeof(action_name), param_name, sizeof(param_name));
618+
sscanf(args_string, "%16s %32s", action_name, param_name);
619619
m_action_param = param_name;
620620

621621
if (!xr_strcmp(action_name, "roundstart"))
@@ -908,7 +908,7 @@ class CCC_BanPlayerByCDKEY : public IConsole_Command
908908
if (!strncmp(args_, LAST_PRINTED_PLAYER_STR, sizeof(LAST_PRINTED_PLAYER_STR) - 1))
909909
{
910910
client_id = last_printed_player;
911-
if (sscanf_s(args_ + sizeof(LAST_PRINTED_PLAYER_STR), "%d", &ban_time) != 1)
911+
if (sscanf(args_ + sizeof(LAST_PRINTED_PLAYER_STR), "%d", &ban_time) != 1)
912912
{
913913
Msg("! ERROR: bad command parameters.");
914914
Msg("Ban player. Format: \"sv_banplayer <player session id | \'%s\'> <ban_time_in_sec>\". To receive "
@@ -921,7 +921,7 @@ class CCC_BanPlayerByCDKEY : public IConsole_Command
921921
else
922922
{
923923
u32 tmp_client_id;
924-
if (sscanf_s(args_, "%u %d", &tmp_client_id, &ban_time) != 2)
924+
if (sscanf(args_, "%u %d", &tmp_client_id, &ban_time) != 2)
925925
{
926926
Msg("! ERROR: bad command parameters.");
927927
Msg("Ban player. Format: \"sv_banplayer <player session id | \'%s\'> <ban_time_in_sec>\". To receive "
@@ -970,7 +970,7 @@ class CCC_BanPlayerByCDKEYDirectly : public IConsole_Command
970970

971971
char hex_digest[64];
972972
s32 ban_time = 0;
973-
if (sscanf_s(args_, "%s %i", &hex_digest, sizeof(hex_digest), &ban_time) != 2)
973+
if (sscanf(args_, "%s %i", &hex_digest, &ban_time) != 2)
974974
{
975975
Msg("! ERROR: bad command parameters.");
976976
Msg("Ban player. Format: \"sv_banplayer_by_digest <hex digest> <ban_time_in_sec>\". To get player hex "
@@ -1012,7 +1012,7 @@ class CCC_UnBanPlayerByIndex : public IConsole_Command
10121012
{
10131013
// size_t ????? u32 maybe?
10141014
size_t player_index = 0;
1015-
if (sscanf_s(args_, "%u", &player_index) != 1)
1015+
if (sscanf(args_, "%u", &player_index) != 1)
10161016
{
10171017
Msg("! ERROR: bad command parameters.");
10181018
Msg(" Unban player. Format: \"sv_unbanplayer <banned player index | \'%s\'>. To receive list of banned "
@@ -1226,7 +1226,7 @@ class CCC_ListPlayers : public IConsole_Command
12261226
exclude_raid_from_args(args, tmp_dest, sizeof(tmp_dest));
12271227
if (xr_strlen(tmp_dest))
12281228
{
1229-
sscanf_s(tmp_dest, "%s", filter_string, sizeof(filter_string));
1229+
sscanf(tmp_dest, "%s", filter_string);
12301230
tmp_functor.filter_string = filter_string;
12311231
}
12321232
}
@@ -1323,7 +1323,7 @@ class CCC_ListPlayers_Banned : public IConsole_Command
13231323
exclude_raid_from_args(args, tmp_dest, sizeof(tmp_dest));
13241324
if (xr_strlen(tmp_dest))
13251325
{
1326-
sscanf_s(tmp_dest, "%s", filter_dest, sizeof(filter_dest));
1326+
sscanf(tmp_dest, "%s", filter_dest);
13271327
}
13281328
tmp_sv_game->PrintBanList(filter_dest);
13291329
Level().Server->Print_Banned_Addreses();
@@ -1356,8 +1356,7 @@ class CCC_ChangeLevelGameType : public IConsole_Command
13561356
string256 GameType;
13571357
GameType[0] = 0;
13581358

1359-
sscanf_s(args, "%255s %255s %255s", LevelName, sizeof(LevelName), LevelVersion, sizeof(LevelVersion), GameType,
1360-
sizeof(GameType));
1359+
sscanf(args, "%255s %255s %255s", LevelName, LevelVersion, GameType);
13611360

13621361
EGameIDs GameTypeID = ParseStringToGameType(GameType);
13631362
if (GameTypeID == eGameIDNoGame)
@@ -1450,7 +1449,7 @@ class CCC_ChangeLevel : public CCC_ChangeLevelGameType
14501449
string256 LevelVersion;
14511450
LevelName[0] = 0;
14521451
LevelVersion[0] = 0;
1453-
sscanf_s(args, "%255s %255s", LevelName, sizeof(LevelName), LevelVersion, sizeof(LevelVersion));
1452+
sscanf(args, "%255s %255s", LevelName, LevelVersion);
14541453

14551454
string1024 argsNew;
14561455
xr_sprintf(argsNew, "%s %s %s", LevelName, LevelVersion, Level().Server->GetGameState()->type_name());

src/xrGame/game_cl_capture_the_artefact.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ void game_cl_CaptureTheArtefact::OnVoteStart(NET_Packet& P)
12611261
command[psize - 1] = 0;
12621262
player[psize - 1] = 0;
12631263

1264-
sscanf_s(command, "%s", cmd_name, psize);
1264+
sscanf(command, "%s", cmd_name);
12651265
u32 cmd_len = xr_strlen(cmd_name);
12661266
u32 tcmd_len = cmd_len;
12671267

@@ -1276,8 +1276,7 @@ void game_cl_CaptureTheArtefact::OnVoteStart(NET_Packet& P)
12761276
Msg("---Vote command: %s", cmd_name);
12771277
#endif
12781278

1279-
int args_count = sscanf_s(command + cmd_len, scans_format, args[0], psize + 1, args[1], psize + 1, args[2],
1280-
psize + 1, args[3], psize + 1, args[4], psize + 1);
1279+
int args_count = sscanf(command + cmd_len, scans_format, args[0], args[1], args[2], args[3], args[4]);
12811280
if (args_count < 0)
12821281
args_count = 0;
12831282

0 commit comments

Comments
 (0)