From 5808fcbb7b03454f37963bcc44a534deef66a1b0 Mon Sep 17 00:00:00 2001 From: Hyunjee Kim Date: Tue, 31 Mar 2020 15:21:54 +0900 Subject: [PATCH] Add exceptions for utext, unormalization, uscript and unumsys Change-Id: I9ea98b6506a42dfec6efb43ff56bba65f9eaad3e Signed-off-by: Hyunjee Kim --- src/utils_i18n_unormalization.c | 12 ++++++++++++ src/utils_i18n_unumsys.c | 2 ++ src/utils_i18n_uscript.c | 9 ++++++++- src/utils_i18n_utext.c | 10 ++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/utils_i18n_unormalization.c b/src/utils_i18n_unormalization.c index cf73822..94cbdea 100644 --- a/src/utils_i18n_unormalization.c +++ b/src/utils_i18n_unormalization.c @@ -46,6 +46,8 @@ int i18n_unormalization_normalize(i18n_unormalizer_h normalizer, const i18n_ucha int i18n_unormalization_get_nfc_instance(i18n_unormalizer_h* normalizer) { + retv_if(normalizer == NULL, I18N_ERROR_INVALID_PARAMETER); + i18n_error_code_e i18n_error; UErrorCode icu_error = U_ZERO_ERROR; @@ -58,6 +60,8 @@ int i18n_unormalization_get_nfc_instance(i18n_unormalizer_h* normalizer) int i18n_unormalization_get_nfd_instance(i18n_unormalizer_h* normalizer) { + retv_if(normalizer == NULL, I18N_ERROR_INVALID_PARAMETER); + i18n_error_code_e i18n_error; UErrorCode icu_error = U_ZERO_ERROR; @@ -70,6 +74,8 @@ int i18n_unormalization_get_nfd_instance(i18n_unormalizer_h* normalizer) int i18n_unormalization_get_nfkc_instance(i18n_unormalizer_h* normalizer) { + retv_if(normalizer == NULL, I18N_ERROR_INVALID_PARAMETER); + i18n_error_code_e i18n_error; UErrorCode icu_error = U_ZERO_ERROR; @@ -82,6 +88,8 @@ int i18n_unormalization_get_nfkc_instance(i18n_unormalizer_h* normalizer) int i18n_unormalization_get_nfkd_instance(i18n_unormalizer_h* normalizer) { + retv_if(normalizer == NULL, I18N_ERROR_INVALID_PARAMETER); + i18n_error_code_e i18n_error; UErrorCode icu_error = U_ZERO_ERROR; @@ -94,6 +102,8 @@ int i18n_unormalization_get_nfkd_instance(i18n_unormalizer_h* normalizer) int i18n_unormalization_get_nfkc_casefold_instance(i18n_unormalizer_h* normalizer) { + retv_if(normalizer == NULL, I18N_ERROR_INVALID_PARAMETER); + i18n_error_code_e i18n_error; UErrorCode icu_error = U_ZERO_ERROR; @@ -107,6 +117,8 @@ int i18n_unormalization_get_nfkc_casefold_instance(i18n_unormalizer_h* normalize int i18n_unormalization_create_filtered(i18n_unormalizer_h normalizer, const i18n_uset_h *filter_set, i18n_unormalizer_h *normalizer2) { + retv_if(normalizer == NULL || normalizer2 == NULL, I18N_ERROR_INVALID_PARAMETER); + i18n_error_code_e i18n_error; UErrorCode icu_error = U_ZERO_ERROR; diff --git a/src/utils_i18n_unumsys.c b/src/utils_i18n_unumsys.c index 9e1d9ec..d48e11c 100644 --- a/src/utils_i18n_unumsys.c +++ b/src/utils_i18n_unumsys.c @@ -50,6 +50,8 @@ void i18n_unumsys_destroy(i18n_unumsys_h unumsys) int i18n_unumsys_get_available_names(i18n_uenumeration_h *uenum) { + retv_if(uenum == NULL, I18N_ERROR_INVALID_PARAMETER); + i18n_error_code_e i18n_error; UErrorCode icu_error = U_ZERO_ERROR; diff --git a/src/utils_i18n_uscript.c b/src/utils_i18n_uscript.c index 31542b0..a83408a 100644 --- a/src/utils_i18n_uscript.c +++ b/src/utils_i18n_uscript.c @@ -21,6 +21,8 @@ int i18n_uscript_get_codes(const char* language, i18n_uscript_code_e* codes, int32_t capacity, int32_t *length) { + retv_if(length == NULL, I18N_ERROR_INVALID_PARAMETER); + i18n_error_code_e i18n_error; UErrorCode icu_error = U_ZERO_ERROR; @@ -55,6 +57,8 @@ const char *i18n_uscript_get_short_name(i18n_uscript_code_e script_code) int i18n_uscript_get_script(i18n_uchar32 codepoint, i18n_uscript_code_e *script_code) { + retv_if(script_code == NULL, I18N_ERROR_INVALID_PARAMETER); + i18n_error_code_e i18n_error; UErrorCode icu_error = U_ZERO_ERROR; @@ -79,6 +83,8 @@ i18n_ubool i18n_uscript_has_script(i18n_uchar32 codepoint, i18n_uscript_code_e s int i18n_uscript_get_script_extensions(i18n_uchar32 codepoint, i18n_uscript_code_e *scripts, int32_t capacity, int32_t *length) { + retv_if(length == NULL, I18N_ERROR_INVALID_PARAMETER); + i18n_error_code_e i18n_error; UErrorCode icu_error = U_ZERO_ERROR; @@ -91,7 +97,8 @@ int i18n_uscript_get_script_extensions(i18n_uchar32 codepoint, i18n_uscript_code int i18n_uscript_get_sample_string(i18n_uscript_code_e script, i18n_uchar *sample, int32_t capacity, int32_t *length) { - retv_if(script >= I18N_USCRIPT_CODE_LIMIT || script <= I18N_USCRIPT_INVALID_CODE, I18N_USCRIPT_INVALID_CODE); + retv_if(length == NULL || + script >= I18N_USCRIPT_CODE_LIMIT || script <= I18N_USCRIPT_INVALID_CODE, I18N_USCRIPT_INVALID_CODE); i18n_error_code_e i18n_error; UErrorCode icu_error = U_ZERO_ERROR; diff --git a/src/utils_i18n_utext.c b/src/utils_i18n_utext.c index 4abc74f..1cf801c 100644 --- a/src/utils_i18n_utext.c +++ b/src/utils_i18n_utext.c @@ -27,6 +27,8 @@ void i18n_utext_destroy(i18n_utext_h ut) int i18n_utext_create_for_UTF8(i18n_utext_h uta, const char *s, int64_t length, i18n_utext_h *utb) { + retv_if(utb == NULL, I18N_ERROR_INVALID_PARAMETER); + i18n_error_code_e i18n_error; UErrorCode icu_error = U_ZERO_ERROR; @@ -39,6 +41,8 @@ int i18n_utext_create_for_UTF8(i18n_utext_h uta, const char *s, int64_t length, int i18n_utext_create_for_uchars(i18n_utext_h uta, const i18n_uchar *s, int64_t length, i18n_utext_h *utb) { + retv_if(utb == NULL, I18N_ERROR_INVALID_PARAMETER); + i18n_error_code_e i18n_error; UErrorCode icu_error = U_ZERO_ERROR; @@ -65,6 +69,12 @@ int i18n_utext_clone(i18n_utext_h dest, const i18n_utext_h src, i18n_ubool deep, i18n_ubool i18n_utext_equals(const i18n_utext_h a, const i18n_utext_h b) { + if(a == NULL || b == NULL) { + set_last_result(I18N_ERROR_INVALID_PARAMETER); + return false; + } + + set_last_result(I18N_ERROR_NONE); return utext_equals((UText *)a, (UText *)b); } -- 2.7.4