]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
intlconv_utf8safestr: do not return NULL but empty string when max_size is zero
authorJaroslav Kysela <perex@perex.cz>
Fri, 29 May 2015 18:41:11 +0000 (20:41 +0200)
committerJaroslav Kysela <perex@perex.cz>
Fri, 29 May 2015 18:46:30 +0000 (20:46 +0200)
src/intlconv.c

index eebee76926e00bee79fdbfc8c3eb52ddd2c3f678..0856ab7ed58852cf8162481e4b767ad30443cf5c 100644 (file)
@@ -166,9 +166,15 @@ intlconv_utf8safestr( const char *dst_charset_id,
                       const char *src_utf8,
                       size_t max_size )
 {
-  char *str = alloca(max_size), *res;
-  ssize_t r = intlconv_utf8(str, max_size, dst_charset_id, src_utf8);
+  char *str, *res;
+  ssize_t r;
   size_t i;
+
+  if (max_size == 0 || *src_utf8 == '\0')
+    return strdup("");
+
+  str = alloca(max_size);
+  r = intlconv_utf8(str, max_size, dst_charset_id, src_utf8);
   if (r <= 0)
     return NULL;
   if (r >= max_size)