Skip to content

Commit

Permalink
Prevent length wraparound in RichString_rewind()
Browse files Browse the repository at this point in the history
The computed length could wrap to a negative integer, causing undefined
behavior.

(Currently it would cause out-of-bound array access due to a signed
length property in RichString. The length property should be migrated
to an unsigned size_t type, but that would be done in a later commit.)

Signed-off-by: Kang-Che Sung <[email protected]>
  • Loading branch information
Explorer09 committed Jan 13, 2025
1 parent f5d9fe8 commit 64e9142
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion RichString.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static void RichString_setLen(RichString* this, int len) {
}

void RichString_rewind(RichString* this, int count) {
RichString_setLen(this, this->chlen - count);
RichString_setLen(this, this->chlen > count ? this->chlen - count : 0);
}

#ifdef HAVE_LIBNCURSESW
Expand Down

0 comments on commit 64e9142

Please sign in to comment.