From c282663a96ae9704a59c55c9300dbc8c49e0ef39 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Mon, 18 Nov 2019 09:41:22 -0800 Subject: Add sanity checks for overwriting buffers --- Source/PuzzleSerializer.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Source/PuzzleSerializer.cpp') diff --git a/Source/PuzzleSerializer.cpp b/Source/PuzzleSerializer.cpp index c1e93a5..e845578 100644 --- a/Source/PuzzleSerializer.cpp +++ b/Source/PuzzleSerializer.cpp @@ -1,5 +1,6 @@ #include "PuzzleSerializer.h" #include "Memory.h" +#include #pragma warning (disable:26451) #pragma warning (disable:26812) @@ -47,6 +48,16 @@ void PuzzleSerializer::WritePuzzle(const Puzzle& p, int id) { WriteDecorations(p, id); WriteSequence(p, id); +#ifndef NDEBUG + int maxDots = _memory->ReadEntityData(id, NUM_DOTS, 1)[0]; + assert(_intersectionFlags.size() <= maxDots); + assert(_intersectionLocations.size() <= maxDots*2); + + int maxConnections = _memory->ReadEntityData(id, NUM_CONNECTIONS, 1)[0]; + assert(_connectionsA.size() <= maxConnections); + assert(_connectionsB.size() <= maxConnections); +#endif + _memory->WriteEntityData(id, GRID_SIZE_X, {(p.width + 1)/2}); _memory->WriteEntityData(id, GRID_SIZE_Y, {(p.height + 1)/2}); _memory->WriteEntityData(id, NUM_DOTS, {static_cast(_intersectionFlags.size())}); @@ -376,6 +387,10 @@ void PuzzleSerializer::WriteDecorations(const Puzzle& p, int id) { } } +#ifndef NDEBUG + int maxDecorations = _memory->ReadEntityData(id, NUM_DECORATIONS, 1)[0]; + assert(decorations.size() < maxDecorations); +#endif _memory->WriteEntityData(id, NUM_DECORATIONS, {static_cast(decorations.size())}); _memory->WriteArray(id, DECORATIONS, decorations); } -- cgit 1.4.1