Mercurial > octave
changeset 26475:9baba1815f1c stable
uniconv-wrappers.c: Fix static analyzer detected issues (bug #55347).
* uniconv-wrappers.c (u8_from_wchar, u8_to_wchar): Check for valid pointer from
malloc before proceeding.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 06 Jan 2019 21:32:21 -0800 |
parents | c69b7519d7eb |
children | 54ad1294ed70 |
files | liboctave/wrappers/uniconv-wrappers.c |
diffstat | 1 files changed, 17 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/wrappers/uniconv-wrappers.c Sun Jan 06 17:58:39 2019 -0800 +++ b/liboctave/wrappers/uniconv-wrappers.c Sun Jan 06 21:32:21 2019 -0800 @@ -76,9 +76,14 @@ // result might not be 0 terminated char *retval = malloc (length + 1); - memcpy (retval, mbchar, length); - free ((void *) mbchar); - retval[length] = 0; // 0 terminate string + if (retval) + { + memcpy (retval, mbchar, length); + free ((void *) mbchar); + retval[length] = 0; // 0 terminate string + } + else + free ((void *) mbchar); return retval; } @@ -98,9 +103,15 @@ src, srclen, NULL, NULL, &length); // result might not be 0 terminated wchar_t *retval = malloc (length + 1 * sizeof (wchar_t)); - memcpy (retval, wchar, length); - free ((void *) wchar); - retval[length / sizeof (wchar_t)] = 0; // 0 terminate string + if (retval) + { + memcpy (retval, wchar, length); + free ((void *) wchar); + retval[length / sizeof (wchar_t)] = 0; // 0 terminate string + } + + else + free ((void *) wchar); return retval; }