Skip to content

Commit

Permalink
Use M_stat for safer save date check and fix Strife save timestamp (#…
Browse files Browse the repository at this point in the history
…1219)

Fixes #1218, thanks @maxmanium for pointing out!

* Use `M_stat`, safe check and fix Strife save date/time
* M_stat: check for success return value

Co-Authored-By: Roman Fomin <rfomin@gmail.com>
  • Loading branch information
JNechaevsky and rfomin authored Aug 27, 2024
1 parent 8c5d000 commit edc1e6e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/doom/m_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,8 @@ static void M_DrawSaveLoadBottomLine(void)
struct stat st;
char filedate[32];

stat(P_SaveGameFile(itemOn), &st);

if (M_stat(P_SaveGameFile(itemOn), &st) == 0)
{
// [FG] suppress the most useless compiler warning ever
#if defined(__GNUC__)
#pragma GCC diagnostic push
Expand All @@ -885,6 +885,7 @@ static void M_DrawSaveLoadBottomLine(void)
#pragma GCC diagnostic pop
#endif
M_WriteText(ORIGWIDTH/2-M_StringWidth(filedate)/2, y + 8, filedate);
}
}

dp_translation = NULL;
Expand Down
4 changes: 3 additions & 1 deletion src/heretic/mn_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,8 @@ static void DrawSaveLoadBottomLine(const Menu_t *menu)
struct stat st;
char filedate[32];

stat(SV_Filename(CurrentItPos), &st);
if (M_stat(SV_Filename(CurrentItPos), &st) == 0)
{
// [FG] suppress the most useless compiler warning ever
#if defined(__GNUC__)
# pragma GCC diagnostic push
Expand All @@ -986,6 +987,7 @@ static void DrawSaveLoadBottomLine(const Menu_t *menu)
# pragma GCC diagnostic pop
#endif
MN_DrTextA(filedate, ORIGWIDTH / 2 - MN_TextAWidth(filedate) / 2, y + 10);
}
}

dp_translation = NULL;
Expand Down
4 changes: 3 additions & 1 deletion src/hexen/mn_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,8 @@ static void DrawSaveLoadBottomLine(const Menu_t *menu)
char filename[100];

M_snprintf(filename, sizeof(filename), "%shex%d.hxs", SavePath, CurrentItPos + (savepage * 10));
stat(filename, &st);
if (M_stat(filename, &st) == 0)
{
// [FG] suppress the most useless compiler warning ever
#if defined(__GNUC__)
# pragma GCC diagnostic push
Expand All @@ -964,6 +965,7 @@ static void DrawSaveLoadBottomLine(const Menu_t *menu)
# pragma GCC diagnostic pop
#endif
MN_DrTextA(filedate, ORIGWIDTH / 2 - MN_TextAWidth(filedate) / 2, y + 10);
}
}

dp_translation = NULL;
Expand Down
1 change: 1 addition & 0 deletions src/m_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ int M_stat(const char *path, struct stat *buf)
// incompatible with struct stat*. We copy only the required compatible
// field.
buf->st_mode = wbuf.st_mode;
buf->st_mtime = wbuf.st_mtime; // [crispy]

free(wpath);

Expand Down
5 changes: 3 additions & 2 deletions src/strife/m_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,8 @@ static void M_DrawSaveLoadBottomLine(void)
struct stat st;
char filedate[32];

stat(P_SaveGameFile(itemOn), &st);

if (M_stat(P_SaveGameFile(itemOn), &st) == 0)
{
// [FG] suppress the most useless compiler warning ever
#if defined(__GNUC__)
#pragma GCC diagnostic push
Expand All @@ -876,6 +876,7 @@ static void M_DrawSaveLoadBottomLine(void)
#pragma GCC diagnostic pop
#endif
M_WriteText(ORIGWIDTH/2-M_StringWidth(filedate)/2, y, filedate);
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/strife/p_saveg.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ char *P_SaveGameFile(int slot)
filename = malloc(filename_size);
}

DEH_snprintf(basename, 32, SAVEGAMENAME "%d.dsg", slot);
// [crispy] changed to Strife savegame file name,
// used by M_DrawSaveLoadBottomLine to show savegame date and time
DEH_snprintf(basename, 32, "strfsav%d.ssg/name", slot);

M_snprintf(filename, filename_size, "%s%s", savegamedir, basename);

Expand Down

0 comments on commit edc1e6e

Please sign in to comment.