diff options
author | cflip <cflip@cflip.net> | 2022-03-23 18:00:54 -0600 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2022-03-23 18:00:54 -0600 |
commit | 3a5bd83ebae5bb4a3536e1af1d117bff2db61073 (patch) | |
tree | af2baa3c8db2354fcc37cc37ff4e3e29563c68ad | |
parent | ff32f311e2b6c554e4f7b91ad42cee44abdd9c40 (diff) |
Prevent oversized levels from saving
The current level format uses bytes to store the width and height, so
levels that are larger than that are not allowed to be saved.
I don't think that the game will need levels larger than 255x255, but
if it does then the level format can be updated.
-rw-r--r-- | src/level.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/level.cpp b/src/level.cpp index 5fa4619..bf94d95 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -130,6 +130,12 @@ void Level::save() const return; } + if (m_width > 255 || m_height > 255) { + std::cerr << "Failed to save level!\n" + << "Level save format does not allow widths or heights greater than 255\n"; + return; + } + outputStream.write((char*)&m_width, 1); outputStream.write((char*)&m_height, 1); outputStream.write((char*)m_tiles, m_width * m_height); |