summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik de Castro Lopo <erikd@mega-nerd.com>2017-01-19 20:28:18 +1100
committerErik de Castro Lopo <erikd@mega-nerd.com>2017-01-19 20:31:34 +1100
commitada48f59f5e23273785deb3bed173589f1d2db37 (patch)
treec83698dd77262418c81450e19f27568a8745f984
parent3be455142ba0441158e1d0db4351e22d71e0f042 (diff)
downloadflac-ada48f59f5e23273785deb3bed173589f1d2db37.tar.gz
share/utf8/charset.c: Cleanup realloc() usage
This version should be logically identical to the previous version but prevents a false-positive from the cppcheck static analysis tool.
-rw-r--r--src/share/utf8/charset.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/share/utf8/charset.c b/src/share/utf8/charset.c
index 4c471694..5c5693d1 100644
--- a/src/share/utf8/charset.c
+++ b/src/share/utf8/charset.c
@@ -485,7 +485,7 @@ int charset_convert(const char *fromcode, const char *tocode,
{
int ret = 0;
struct charset *charset1, *charset2;
- char *tobuf, *p, *newbuf;
+ char *tobuf, *p;
int i, j, wc;
charset1 = charset_find(fromcode);
@@ -520,8 +520,10 @@ int charset_convert(const char *fromcode, const char *tocode,
*tolen = p - tobuf;
*p++ = '\0';
if (to) {
- newbuf = realloc(tobuf, p - tobuf);
- *to = newbuf ? newbuf : tobuf;
+ char *tobuf_saved = tobuf;
+ *to = realloc(tobuf, p - tobuf);
+ if (*to == NULL)
+ *to = tobuf_saved;
}
else
free(tobuf);