From 4c9e1733ecd6486cccf75ec027286e869bb46012 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 6 Mar 2014 17:22:41 +0530 Subject: [PATCH] Return NULL when decoding from UTF-32 fails --- src/calibre/utils/icu_calibre_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/utils/icu_calibre_utils.h b/src/calibre/utils/icu_calibre_utils.h index c9a5147ef2..88cff6491e 100644 --- a/src/calibre/utils/icu_calibre_utils.h +++ b/src/calibre/utils/icu_calibre_utils.h @@ -46,7 +46,7 @@ static UChar* python_to_icu(PyObject *obj, int32_t *osz, uint8_t do_check) { ans = (UChar*) calloc(2*sz+1, sizeof(UChar)); // There can be no more than 2 UChars per character if (ans == NULL) { PyErr_NoMemory(); goto end; } u_strFromUTF32(ans, (int32_t)2*sz+1, osz, (UChar32*)PyUnicode_AS_UNICODE(obj), (int32_t)sz, &status); - if (U_FAILURE(status)) { PyErr_SetString(PyExc_ValueError, u_errorName(status)); goto end; } + if (U_FAILURE(status)) { PyErr_SetString(PyExc_ValueError, u_errorName(status)); free(ans); ans = NULL; goto end; } } end: return ans;