Fix use-after-free warning in GCC 12

A pointer was used for arithmatic after a realloc.

Co-authored-by: Alexia Massalin <alexia@lambda.csail.mit.edu>
This commit is contained in:
Martijn van Beurden 2023-04-14 11:39:14 +02:00
parent fd842b6a3b
commit c623f0f42c
1 changed files with 4 additions and 3 deletions

View File

@ -62,7 +62,7 @@ int iconvert(const char *fromcode, const char *tocode,
char *ib;
char *ob;
char *utfbuf = 0, *outbuf, *newbuf;
size_t utflen, outlen, ibl, obl, k;
size_t utflen, outlen, ibl, obl, obp, k;
char tbuf[2048];
cd1 = iconv_open("UTF-8", fromcode);
@ -124,11 +124,12 @@ int iconvert(const char *fromcode, const char *tocode,
if(utflen*2 < utflen) /* overflow check */
goto fail;
utflen *= 2;
obp = ob - utfbuf; /* save position */
newbuf = realloc(utfbuf, utflen);
if (!newbuf)
goto fail;
ob = (ob - utfbuf) + newbuf;
obl = utflen - (ob - newbuf);
ob = newbuf + obp;
obl = utflen - obp;
utfbuf = newbuf;
}
else {