diff --git a/src/string_utils.c b/src/string_utils.c index 6480973d..69958cad 100644 --- a/src/string_utils.c +++ b/src/string_utils.c @@ -206,15 +206,22 @@ char *utf8_case(const char *s, casing_option_t casing, utf8proc_option_t options } else if (casing == UTF8_UPPER) { norm = utf8proc_toupper(uc); } + buffer[i] = norm; } result = utf8proc_reencode(buffer, result, options); + if (result < 0) { + free(buffer); + return NULL; + } - utf8proc_int32_t *newptr; - newptr = (utf8proc_int32_t *) realloc(buffer, (size_t)result+1); - if (newptr) buffer = newptr; - - free(buffer); + utf8proc_int32_t *newptr = (utf8proc_int32_t *) realloc(buffer, (size_t)result+1); + if (newptr != NULL) { + buffer = newptr; + } else { + free(buffer); + return NULL; + } return (char *)buffer; } diff --git a/src/string_utils.h b/src/string_utils.h index 6bf009d7..32b57c3d 100644 --- a/src/string_utils.h +++ b/src/string_utils.h @@ -41,7 +41,7 @@ Utilities for manipulating strings in C. #define UTF8PROC_OPTIONS_STRIP_ACCENTS UTF8PROC_OPTIONS_BASE | UTF8PROC_DECOMPOSE | UTF8PROC_STRIPMARK // Lowercase -#define UTF8PROC_OPTIONS_LOWERCASE UTF8PROC_OPTIONS_BASE | UTF8PROC_CASEFOLD +#define UTF8PROC_OPTIONS_CASE_FOLD UTF8PROC_OPTIONS_BASE | UTF8PROC_CASEFOLD // ASCII string methods