From 62a31ba6c92e684c90529a3ee6dcc2b1e4142a31 Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Thu, 8 Dec 2022 21:14:50 +0000 Subject: Fix potential NULL dereferences (thanks, GCC!) Also fix some English in the API for enchant_dict_suggest, the implicated function. --- src/enchant.h | 4 ++-- src/lib.c | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/enchant.h b/src/enchant.h index 20e2d24..2211fa4 100644 --- a/src/enchant.h +++ b/src/enchant.h @@ -170,8 +170,8 @@ int enchant_dict_check (EnchantDict * dict, const char *const word, ssize_t len) * @len: The byte length of @word, or -1 for strlen (@word) * @out_n_suggs: The location to store the # of suggestions returned, or %null * - * Will return an %null value if any of those pre-conditions - * are not met. + * Will return a %null value if any of those pre-conditions + * is not met. * * Returns: A %null terminated list of UTF-8 encoded suggestions, or %null */ diff --git a/src/lib.c b/src/lib.c index 85fcce5..0a10ebc 100644 --- a/src/lib.c +++ b/src/lib.c @@ -548,8 +548,11 @@ enchant_dict_suggest (EnchantDict * dict, const char *const word, ssize_t len, s if (n_suggs > 0) { suggs = g_new0 (char *, n_suggs + 1); - n_suggs = enchant_dict_merge_suggestions(suggs, 0, dict_suggs, n_dict_suggs); - n_suggs = enchant_dict_merge_suggestions(suggs, n_suggs, pwl_suggs, n_pwl_suggs); + n_suggs = 0; + if (dict_suggs != NULL) + n_suggs = enchant_dict_merge_suggestions(suggs, n_suggs, dict_suggs, n_dict_suggs); + if (pwl_suggs != NULL) + n_suggs = enchant_dict_merge_suggestions(suggs, n_suggs, pwl_suggs, n_pwl_suggs); } g_strfreev(dict_suggs); -- cgit v1.2.1