Skip to content

SW: Simplify game's command history to remove a bunch of strcpy()s. Also fixes ASAN error.

sirlemonhead requested to merge sirlemonhead/eduke32:voidsw-history into master

ASAN was reporting that the function CON_AddHistory() was indexing the command_history array with -1.

The code maintains a FIFO buffer of the last 20 commands the user has typed. When adding a new command, it'd loop through the history array, moving each item up by one position, and then adding the new command in the command_history[0] position. The highest position command in the array would be overwritten by the one before it.

Due to how the code was written, it'd end up accessing the command_history array at the -1 position during the loop.

Rewrote the function to use an index value 'add_history_pos', adding the new item after the previous one. The index loops back to 0 when it's reached the end of the array, and thus maintains the FIFOness.

This removes a bunch of strcpy() calls. It also will no longer do any invalid array accesses.

Merge request reports

Loading