Commit 778901d0 authored by Philipp Kutin's avatar Philipp Kutin
Browse files

duke32: in savegame.cpp, use Bstrncpyz() for copying from/to '_savehead::boardfn'.

With 'RELEASE := 0', gcc (Raspbian 8.3.0-6+rpi1) 8.3.0 said:

 savegame.cpp: In function 'int32_t G_LoadPlayer(savebrief_t&)':
 savegame.cpp:655:12: warning: 'void* memcpy(void*, const void*, size_t)' offset [297, 328]
   from the object at 'h' is out of the bounds of referenced subobject '_savehead::boardfn'
   with type 'char [224]' at offset 72 [-Warray-bounds]
      Bmemcpy(boardfilename, h.boardfn, sizeof(boardfilename));

It also emits many warnings about possible truncation with (B)snprintf(),
presumably based on computed upper bounds on the length of the input varargs.

Also, resurrect static assert for post-commit-687000e2 situation and
remove comment referencing a tag which was removed in commit bd3a933a.
parent e2ba35f2
......@@ -649,10 +649,10 @@ int32_t G_LoadPlayer(savebrief_t & sv)
ud.m_level_number = h.levnum;
ud.m_player_skill = h.skill;
// NOTE: Bmemcpy needed for SAVEGAME_MUSIC.
// EDUKE32_STATIC_ASSERT(sizeof(boardfilename) == sizeof(h.boardfn));
EDUKE32_STATIC_ASSERT(sizeof(h.boardfn) < sizeof(boardfilename));
different_user_map = Bstrncmp(boardfilename, h.boardfn, sizeof(h.boardfn));
Bmemcpy(boardfilename, h.boardfn, sizeof(boardfilename));
// NOTE: size arg is (unconventionally) that of the source, it being smaller.
Bstrncpyz(boardfilename, h.boardfn, sizeof(h.boardfn) /*!*/);
int const mapIdx = h.volnum*MAXLEVELS + h.levnum;
......@@ -1669,9 +1669,7 @@ int32_t sv_saveandmakesnapshot(buildvfs_FILE fil, char const *name, int8_t spot,
h.levnum = ud.level_number;
h.skill = ud.player_skill;
const uint32_t BSZ = sizeof(h.boardfn);
// EDUKE32_STATIC_ASSERT(BSZ == sizeof(currentboardfilename));
Bstrncpy(h.boardfn, currentboardfilename, BSZ);
Bstrncpyz(h.boardfn, currentboardfilename, sizeof(h.boardfn));
if (spot >= 0)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment