From 662d74f8b687255b0fb1098bfc7db91b6fbbd82d Mon Sep 17 00:00:00 2001 From: Mingjie Shen Date: Fri, 26 May 2023 16:32:34 -0400 Subject: [PATCH] Fix array index used before range check These uses of offset 'ind' should follow the range check. --- src/microrl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/microrl.c b/src/microrl.c index 5bf1962..450c7a3 100644 --- a/src/microrl.c +++ b/src/microrl.c @@ -192,7 +192,7 @@ static int split (microrl_t * pThis, int limit, char const ** tkn_arr) int ind = 0; while (1) { // go to the first whitespace (zerro for us) - while ((pThis->cmdline [ind] == '\0') && (ind < limit)) { + while ((ind < limit) && (pThis->cmdline [ind] == '\0')) { ind++; } if (!(ind < limit)) return i; @@ -201,7 +201,7 @@ static int split (microrl_t * pThis, int limit, char const ** tkn_arr) return -1; } // go to the first NOT whitespace (not zerro for us) - while ((pThis->cmdline [ind] != '\0') && (ind < limit)) { + while ((ind < limit) && (pThis->cmdline [ind] != '\0')) { ind++; } if (!(ind < limit)) return i;