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. Similar issue as in commit c03e650;  in both cases,  Valgrind will complain about the access of an element just past the end of the valid array.
  • Loading branch information
Bill-Gray committed Feb 12, 2025
1 parent 38c7571 commit 5a61709
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pdcurses/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,9 @@ size_t PDC_wcstombs(char *dest, const wchar_t *src, size_t n)
if (!src || !dest)
return 0;

while (*src && i + 4 < n)
while( i + 4 < n && *src)
i += PDC_wc_to_utf8( dest + i, *src++);
while (*src && i < n)
while( i < n && *src)
{
char tbuff[4];
size_t count = (size_t)PDC_wc_to_utf8( tbuff, *src++);
Expand Down

0 comments on commit 5a61709

Please sign in to comment.