From 960df8862136fe834aea5a2e264bce33ab144e41 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 28 Mar 2024 23:14:29 +0100 Subject: [PATCH] cov: validate i before underflow Although it can't happen in this code, ensure 'i' is not 0 before decrementing it. --- lib/display/display.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/display/display.c b/lib/display/display.c index f0a423bbc..262102381 100644 --- a/lib/display/display.c +++ b/lib/display/display.c @@ -999,7 +999,8 @@ char yes_no_prompt(const char *prompt, ...) answer = _no + 1; /* Expecting 'No' */ } else if (!ret && isspace(c)) { /* Ignore any whitespace before */ - --i; + if (i > 0) + i--; goto nextchar; } else if ((ret > 0) && answer && isspace(c)) { /* Ignore any whitespace after */