ncwidth: fix heap overrun

This commit is contained in:
magiblot 2021-09-22 14:58:21 +02:00 committed by nick black
parent 4fa15e4256
commit 7fd93b5977

View File

@ -11,12 +11,12 @@ static int
add_wchar(wchar_t** wbuf, size_t* bufsize, size_t* used, wchar_t wc){ add_wchar(wchar_t** wbuf, size_t* bufsize, size_t* used, wchar_t wc){
if(*used == *bufsize){ if(*used == *bufsize){
const size_t GROW = 128; const size_t GROW = 128;
wchar_t* tmp = realloc(*wbuf, *bufsize + GROW * sizeof(**wbuf)); wchar_t* tmp = realloc(*wbuf, (*bufsize + GROW) * sizeof(**wbuf));
if(tmp == NULL){ if(tmp == NULL){
return -1; return -1;
} }
*wbuf = tmp; *wbuf = tmp;
*bufsize += GROW * sizeof(**wbuf); *bufsize += GROW;
} }
(*wbuf)[*used] = wc; (*wbuf)[*used] = wc;
++*used; ++*used;