Skip to content

Commit 331048d

Browse files
committed
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
1 parent 6a3e97d commit 331048d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/wolfterm.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,15 @@ static void wolfSSH_ClearScreen(WOLFSSH_HANDLE handle, word32 x1, word32 y1, wor
115115
start.Y = y1;
116116

117117
/* get number of cells */
118-
if (y1 == y2) { /* on same line so is x2 - x1 */
119-
fill = x2 - x1;
118+
if (y2 == y1) { /* on same line so is x2 - x1 */
119+
fill = (x2 >= x1) ? (x2 - x1) : 0;
120120
}
121-
else { /* | y1 - y2 | * maxX - x1 + x2 */
122-
fill = y1 - y2;
123-
if (fill < 0)
124-
fill += fill * 2;
125-
fill = fill * maxX - x1 + x2;
121+
/* (y2 - y1) * maxX - x1 + x2 */
122+
else if (y2 > y1) {
123+
fill = (y2 - y1) * maxX - x1 + x2;
124+
}
125+
else {
126+
fill = 0;
126127
}
127128

128129
FillConsoleOutputCharacterA(handle, ' ', fill, start, &w);

0 commit comments

Comments
 (0)