!17 [sync] PR-16: [sync] PR-15: pwl.c: allow the PWL APIs to be passed -1 as word length

From: @openeuler-sync-bot 
Reviewed-by: @lyn1001 
Signed-off-by: @lyn1001
This commit is contained in:
openeuler-ci-bot 2023-11-28 11:17:10 +00:00 committed by Gitee
commit 5d429290e7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 118 additions and 1 deletions

View File

@ -0,0 +1,113 @@
From f6659579ec8f165db7f931eb05717f9f93ef27ef Mon Sep 17 00:00:00 2001
From: Reuben Thomas <rrt@sc3d.org>
Date: Mon, 14 Jun 2021 15:22:33 +0100
Subject: [PATCH] pwl.c: allow the PWL APIs to be passed -1 as word length
This is strictly an API/ABI change, but bump only the minor version, as in
practice it is simply an extension that makes the enchant_pwl_* APIs work
like the enchant_dict_* APIs.
---
configure.ac | 2 +-
src/pwl.c | 22 +++++++++++++++++-----
src/pwl.h | 8 ++++----
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/configure.ac b/configure.ac
index 4877edc..e67163e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([enchant],[2.2.15])
+AC_INIT([enchant],[2.3.0])
AC_CONFIG_SRCDIR(src/enchant.h)
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([subdir-objects])
diff --git a/src/pwl.c b/src/pwl.c
index 4f118a1..db645d5 100644
--- a/src/pwl.c
+++ b/src/pwl.c
@@ -313,8 +313,11 @@ static void enchant_pwl_remove_from_trie(EnchantPWL *pwl,
}
void enchant_pwl_add(EnchantPWL *pwl,
- const char *const word, size_t len)
+ const char *const word, ssize_t len)
{
+ if (len < 0)
+ len = strlen (word);
+
enchant_pwl_refresh_from_file(pwl);
enchant_pwl_add_to_trie(pwl, word, len);
@@ -342,7 +345,7 @@ void enchant_pwl_add(EnchantPWL *pwl,
putc ('\n', f);
}
- if (fwrite (word, sizeof(char), len, f) == len)
+ if (fwrite (word, sizeof(char), len, f) == (size_t)len)
{
putc ('\n', f);
}
@@ -353,8 +356,11 @@ void enchant_pwl_add(EnchantPWL *pwl,
}
void enchant_pwl_remove(EnchantPWL *pwl,
- const char *const word, size_t len)
+ const char *const word, ssize_t len)
{
+ if (len < 0)
+ len = strlen (word);
+
if(enchant_pwl_check(pwl, word, len) == 1)
return;
@@ -525,8 +531,11 @@ static gchar* enchant_utf8_strtitle(const gchar*str, gssize len)
return result;
}
-int enchant_pwl_check(EnchantPWL *pwl, const char *const word, size_t len)
+int enchant_pwl_check(EnchantPWL *pwl, const char *const word, ssize_t len)
{
+ if (len < 0)
+ len = strlen (word);
+
enchant_pwl_refresh_from_file(pwl);
int exists = enchant_pwl_contains(pwl, word, len);
@@ -609,8 +618,11 @@ static int best_distance(char** suggs, const char *const word, size_t len)
/* gives the best set of suggestions from pwl that are at least as good as the
* given suggs (if suggs == NULL just best from pwl) */
char** enchant_pwl_suggest(EnchantPWL *pwl, const char *const word,
- size_t len, char** suggs, size_t* out_n_suggs)
+ ssize_t len, char** suggs, size_t* out_n_suggs)
{
+ if (len < 0)
+ len = strlen (word);
+
int max_dist = suggs ? best_distance(suggs, word, len) : ENCHANT_PWL_MAX_ERRORS;
max_dist = MIN (max_dist, ENCHANT_PWL_MAX_ERRORS);
diff --git a/src/pwl.h b/src/pwl.h
index f713b29..c945e3c 100644
--- a/src/pwl.h
+++ b/src/pwl.h
@@ -42,12 +42,12 @@ typedef struct str_enchant_pwl EnchantPWL;
EnchantPWL* enchant_pwl_init(void);
EnchantPWL* enchant_pwl_init_with_file(const char * file);
-void enchant_pwl_add(EnchantPWL * me, const char *const word, size_t len);
-void enchant_pwl_remove(EnchantPWL * me, const char *const word, size_t len);
-int enchant_pwl_check(EnchantPWL * me,const char *const word, size_t len);
+void enchant_pwl_add(EnchantPWL * me, const char *const word, ssize_t len);
+void enchant_pwl_remove(EnchantPWL * me, const char *const word, ssize_t len);
+int enchant_pwl_check(EnchantPWL * me, const char *const word, ssize_t len);
/*gives the best set of suggestions from pwl that are at least as good as the given suggs*/
char** enchant_pwl_suggest(EnchantPWL *me, const char *const word,
- size_t len, char ** suggs, size_t* out_n_suggs);
+ ssize_t len, char ** suggs, size_t* out_n_suggs);
void enchant_pwl_free(EnchantPWL* me);
#ifdef __cplusplus
--
2.42.0.windows.2

View File

@ -1,11 +1,12 @@
Name: enchant2
Version: 2.2.15
Release: 2
Release: 3
Summary: Generic spell checking library
License: LGPLv2+
URL: https://github.com/AbiWord/enchant
Source0: https://github.com/AbiWord/enchant/releases/download/v%{version}/enchant-%{version}.tar.gz
Patch6000: backport-enchant_aspell.patch
Patch6001: 0001-pwl.c-allow-the-PWL-APIs-to-be-passed-1-as-word-leng.patch
BuildRequires: automake autoconf libtool gcc-c++ glib2-devel aspell-devel hunspell-devel libvoikko-devel
@ -94,6 +95,9 @@ sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g;
%{_mandir}/man1/*
%changelog
* Tue Oct 24 2023 liubo <liubo1@xfusion.com> - 2.2.15-3
- pwl.c: allow the PWL APIs to be passed -1 as word length
* Thu Apr 29 2021 zhaoyuxing <zhaoyuxing2@huawei.com> - 2.2.15-2
- Type:bugfix
- CVE:NA