Skip to content

Commit

Permalink
Array bound checking should be done _before_ checking for null termin…
Browse files Browse the repository at this point in the history
…ators, as per @Hamayama's PDCurses-win10-jp fork.
  • Loading branch information
Bill-Gray committed Mar 14, 2021
1 parent 057fbc6 commit c03e650
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pdcurses/addstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int waddnstr(WINDOW *win, const char *str, int n)
if (!win || !str)
return ERR;

while (str[i] && (i < n || n < 0))
while( (i < n || n < 0) && str[i])
{
#ifdef PDC_WIDE
wchar_t wch;
Expand Down Expand Up @@ -171,6 +171,7 @@ int waddnwstr(WINDOW *win, const wchar_t *wstr, int n)
return ERR;

while (wstr[i] && (i < n || n < 0))
while( (i < n || n < 0) && wstr[i])
{
chtype wch = wstr[i++];

Expand Down
2 changes: 1 addition & 1 deletion pdcurses/insstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int winsnstr(WINDOW *win, const char *str, int n)
p = wstr;
i = 0;

while (str[i] && i < n)
while( i < n && str[i])
{
int retval = PDC_mbtowc(p, str + i, n - i);

Expand Down

0 comments on commit c03e650

Please sign in to comment.