Memory-safety fixes. If you downloaded v3.0.0, replace it with this.
What was wrong
Three defects, all reachable by typing numbers at the prompt.
Out-of-bounds read on wide mazes. The row buffer was a fixed char[256],
but the read loop ran to colunas. Anything wider than the buffer read past
its end. AddressSanitizer reports a stack-buffer-overflow on a 300-column
maze in v3.0.0. The buffer is now sized from colunas, and the loop stops at
the number of bytes fgets actually returned — so short rows and truncated
input pad with free space instead of picking up whatever was in memory.
Unchecked scanf. Typing a letter at the Linhas: prompt left linhas
and colunas indeterminate, and the value went on to malloc as a size.
Both reads are checked now.
Unbounded dimensions. linhas * colunas could overflow int and yield an
undersized BFS queue. Both are now capped at 1000, which keeps the product
inside an int with room to spare — and a board bigger than that cannot be
animated in a terminal anyway.
Every allocation is checked as well, which also fixes a leak on the "start or
destination is blocked" exit path.
One behaviour change worth knowing: a row longer than the declared width is
now truncated and the excess discarded, so it can no longer desynchronise the
row after it.
How this was verified
ASan + UBSan + LeakSanitizer over eleven inputs — 5×5, 3×300, non-numeric
dimensions, oversized dimensions, negative dimensions, short rows, over-long
rows, blocked start, unreachable destination, truncated input, and 1×1. No
findings. The same suite reproduces the stack overflow on v3.0.0, so the fix
is tied to an observed failure rather than to code review alone.
Both binaries build warning-free at -std=gnu17 -Wall -Wextra -O2, on GCC
16.1.1 and mingw-w64 GCC 16.1.0. robot-maze.exe was run under Wine 11.14 —
correct path, exit 0, and the new dimension check fires. Still not tested on
real Windows. The .deb was checked by inspection, not installed with
dpkg.
Which file to download
| Asset | For |
|---|---|
robot-maze.exe |
Windows x86-64. Statically linked — no DLLs needed. |
robot-maze_3.0.1_amd64.deb |
Debian, Ubuntu, Mint, Pop!_OS |
robot-maze-3.0.1-1-x86_64.pkg.tar.zst |
Arch, Manjaro, EndeavourOS |
robot-maze.linux |
Any other Linux x86-64. Needs glibc ≥ 2.34. |
robot-maze-3.0.1-src.tar.gz |
Source |
sudo apt install ./robot-maze_3.0.1_amd64.deb # Debian / Ubuntu
sudo pacman -U robot-maze-3.0.1-1-x86_64.pkg.tar.zst # Arch
chmod +x robot-maze.linux && ./robot-maze.linux # anything elseChecksums
76989ccb994ed9c33bd8c6d910dcfde2644b305cb44ee943b35ab96c7fd893fe robot-maze-3.0.1-1-x86_64.pkg.tar.zst
8083ec793597618e570671fb769f96d93e77f7f35aba575a1183c7070a7f32e6 robot-maze_3.0.1_amd64.deb
be3815b7afd2db59eb9c618a643756b25aa190a4d1c77c1c4ef15685dfa78afb robot-maze-3.0.1-src.tar.gz
f795747fd349954a336bc69a5986de0ec1803773d2666b6057613eedb7df14b9 robot-maze.exe
eaa6fab6e5f2d7da5110ab6027539b5709fbdc3b399094e93d5133835f8a8c28 robot-maze.linux