Skip to content

Make tile data size a constant#157

Merged
DanielaOrtner merged 1 commit into
RebelToolbox:mainfrom
madmiraal:fix-writing-1-byte
Apr 12, 2025
Merged

Make tile data size a constant#157
DanielaOrtner merged 1 commit into
RebelToolbox:mainfrom
madmiraal:fix-writing-1-byte

Conversation

@madmiraal
Copy link
Copy Markdown
Contributor

Currently, gcc is raising an index overflow warning:

scene/2d/tile_map.cpp: In member function 'void TileMap::_set_tile_data(const PoolVector<int>&)':
scene/2d/tile_map.cpp:1528:22: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
 1528 |             local[j] = ptr[j];
      |             ~~~~~~~~~^~~~~~~~
scene/2d/tile_map.cpp:1526:17: note: at offset 12 into destination object 'local' of size 12
 1526 |         uint8_t local[12];
      |                 ^~~~~

This is a false warning. The index will never be 12, because the loop limit will be less than 12 or 8:

for (int j = 0; j < ((format == FORMAT_2) ? 12 : 8); j++) {
local[j] = ptr[j];
}

However, to avoid confusion and prevent the limit being calculated every time, this PR makes the limit (the data size) a constant.

@madmiraal madmiraal added the PR Type: Bug Fix Your current game should now work as expected. label Apr 12, 2025
@DanielaOrtner DanielaOrtner self-requested a review April 12, 2025 12:18
@DanielaOrtner DanielaOrtner merged commit bca55a9 into RebelToolbox:main Apr 12, 2025
@madmiraal madmiraal deleted the fix-writing-1-byte branch April 13, 2025 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR Type: Bug Fix Your current game should now work as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants