From 331048d701f78ef3dcdec50188ab7ed3070ffdfb Mon Sep 17 00:00:00 2001 From: John Safranek Date: Mon, 9 Mar 2026 14:16:57 -0700 Subject: [PATCH] Unsigned variable compared < 0 When filling the screen with spaces, the code was subtracting two unsigned numbers and checking if they were negative. Changed to use a comparison and adjust the subtraction as appropriate, then did the rest of the size expansion. If the second point is before the first, set the fill length to 0. Affected function: wolfSSH_ClearScreen. Issue: F-48 --- src/wolfterm.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/wolfterm.c b/src/wolfterm.c index 5fd23bf8..63e69d67 100644 --- a/src/wolfterm.c +++ b/src/wolfterm.c @@ -115,14 +115,15 @@ static void wolfSSH_ClearScreen(WOLFSSH_HANDLE handle, word32 x1, word32 y1, wor start.Y = y1; /* get number of cells */ - if (y1 == y2) { /* on same line so is x2 - x1 */ - fill = x2 - x1; + if (y2 == y1) { /* on same line so is x2 - x1 */ + fill = (x2 >= x1) ? (x2 - x1) : 0; } - else { /* | y1 - y2 | * maxX - x1 + x2 */ - fill = y1 - y2; - if (fill < 0) - fill += fill * 2; - fill = fill * maxX - x1 + x2; + /* (y2 - y1) * maxX - x1 + x2 */ + else if (y2 > y1) { + fill = (y2 - y1) * maxX - x1 + x2; + } + else { + fill = 0; } FillConsoleOutputCharacterA(handle, ' ', fill, start, &w);