From 0f34b70c90afb487541448ae88ca99d7186e8150 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 14 Apr 2014 18:08:13 +0300 Subject: Move this check before allocation. --- lib/util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/util.c') diff --git a/lib/util.c b/lib/util.c index fa85431..539afa2 100644 --- a/lib/util.c +++ b/lib/util.c @@ -254,6 +254,9 @@ size_t _bmUtf8RuneInsert(char **inOutString, size_t *inOutBufSize, size_t start, if (outRuneWidth) *outRuneWidth = 0; + if (u8len == 1 && !isprint(*rune)) + return 0; + size_t len = (*inOutString ? strlen(*inOutString) : 0); if (!*inOutString && !(*inOutString = calloc(1, (*inOutBufSize = u8len + 1)))) return 0; @@ -273,9 +276,6 @@ size_t _bmUtf8RuneInsert(char **inOutString, size_t *inOutBufSize, size_t start, *inOutBufSize *= 2; } - if (u8len == 1 && !isprint(*rune)) - return 0; - char *str = *inOutString + start; memmove(str + u8len, str, len - start); memcpy(str, rune, u8len); -- cgit v1.2.3-70-g09d2