From 484e995295f1078180a28a5be07767493b3e6aeb Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 24 Nov 2022 17:08:58 +0100 Subject: [PATCH] games: fix string overflow / stack corruption warning: '%1d' directive writing between 1 and 3 bytes into a region of size 2 --- usermods/usermod_v2_games/usermod_v2_games.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usermods/usermod_v2_games/usermod_v2_games.h b/usermods/usermod_v2_games/usermod_v2_games.h index b3895834..a26b5d5a 100644 --- a/usermods/usermod_v2_games/usermod_v2_games.h +++ b/usermods/usermod_v2_games/usermod_v2_games.h @@ -164,8 +164,8 @@ uint16_t mode_pongGame(void) { SEGMENT.setPixelColorXY(vW/2, i, BLUE); } - char tempString[2] = ""; - sprintf(tempString, "%1d%1d", ball->scoreRight, ball->scoreLeft); + char tempString[4] = { '\0' }; + snprintf(tempString, 4, "%1d%1d", ball->scoreRight, ball->scoreLeft); SEGMENT.drawCharacter(tempString[0], vW/2-5, -2, 5, 8, BLUE); SEGMENT.drawCharacter(tempString[1], vW/2+2, -2, 5, 8, BLUE);