Skip to content

Commit 6adb885

Browse files
committed
Fix #79311: enchant_dict_suggest() fails on big endian architecture
For obvious reasons, we must not assign a `size_t` value to an `int` variable using memcpy(). However, there is actually no need for the intermediate `n_sugg_st` here, if we use the proper types in the first place. A regression test is not necessary, because dict_suggest.phpt already exhibits the erroneous behavior on big endian architectures.
1 parent d31fc59 commit 6adb885

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ PHP NEWS
2020
cmb)
2121
. Fixed bug #79271 (DOMDocumentType::$childNodes is NULL). (cmb)
2222

23+
- Enchant:
24+
. Fixed bug #79311 (enchant_dict_suggest() fails on big endian architecture).
25+
(cmb)
26+
2327
- MySQLi:
2428
. Fixed bug #64032 (mysqli reports different client_version). (cmb)
2529

ext/enchant/enchant.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -723,18 +723,16 @@ PHP_FUNCTION(enchant_dict_quick_check)
723723
PHP_ENCHANT_GET_DICT;
724724

725725
if (enchant_dict_check(pdict->pdict, word, wordlen) > 0) {
726-
int n_sugg;
727-
size_t n_sugg_st;
726+
size_t n_sugg;
728727
char **suggs;
729728

730729
if (!sugg && ZEND_NUM_ARGS() == 2) {
731730
RETURN_FALSE;
732731
}
733732

734-
suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg_st);
735-
memcpy(&n_sugg, &n_sugg_st, sizeof(n_sugg));
733+
suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg);
736734
if (suggs && n_sugg) {
737-
int i;
735+
size_t i;
738736
for (i = 0; i < n_sugg; i++) {
739737
add_next_index_string(sugg, suggs[i]);
740738
}
@@ -776,19 +774,17 @@ PHP_FUNCTION(enchant_dict_suggest)
776774
size_t wordlen;
777775
char **suggs;
778776
enchant_dict *pdict;
779-
int n_sugg;
780-
size_t n_sugg_st;
777+
size_t n_sugg;
781778

782779
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &dict, &word, &wordlen) == FAILURE) {
783780
RETURN_FALSE;
784781
}
785782

786783
PHP_ENCHANT_GET_DICT;
787784

788-
suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg_st);
789-
memcpy(&n_sugg, &n_sugg_st, sizeof(n_sugg));
785+
suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg);
790786
if (suggs && n_sugg) {
791-
int i;
787+
size_t i;
792788

793789
array_init(return_value);
794790
for (i = 0; i < n_sugg; i++) {

0 commit comments

Comments
 (0)