From 24de3b6ac9145c4ea144cda05d6dba77b35af14a Mon Sep 17 00:00:00 2001 From: lacatoire Date: Sun, 16 Aug 2026 11:46:40 +0200 Subject: [PATCH] Fix enchant_broker_set_dict_path() and enchant_broker_get_dict_path() returning null Both function bodies sit entirely inside #ifdef HAVE_ENCHANT_BROKER_SET_PARAM, with nothing after the #endif. That macro is only defined on the legacy libenchant 1.x path of config.m4, since enchant_broker_set_param() was removed in libenchant 2, so on every build linked against enchant-2 the functions fall off the end and return null, violating their declared bool and string|false return types. Return false on that path instead, which is the value both functions already use for every in-band failure. The two existing tests are skipped on libenchant 2, so the broken path had no coverage; a test is added for it. --- ext/enchant/enchant.c | 8 ++++++++ ext/enchant/tests/dict_path_libenchant2.phpt | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 ext/enchant/tests/dict_path_libenchant2.phpt diff --git a/ext/enchant/enchant.c b/ext/enchant/enchant.c index a109c24062f0..0ca04b8b2f7f 100644 --- a/ext/enchant/enchant.c +++ b/ext/enchant/enchant.c @@ -348,6 +348,11 @@ PHP_FUNCTION(enchant_broker_set_dict_path) default: RETURN_FALSE; } +#else + /* enchant_broker_set_param() was removed in libenchant 2, so this build has + * no dictionary path support. Report the failure instead of falling off the + * end of the function, which would return null and violate the return type. */ + RETURN_FALSE; #endif } /* }}} */ @@ -387,6 +392,9 @@ PHP_FUNCTION(enchant_broker_get_dict_path) } RETURN_STRING(value); +#else + /* See enchant_broker_set_dict_path(). */ + RETURN_FALSE; #endif } /* }}} */ diff --git a/ext/enchant/tests/dict_path_libenchant2.phpt b/ext/enchant/tests/dict_path_libenchant2.phpt new file mode 100644 index 000000000000..b06da5ef0d4e --- /dev/null +++ b/ext/enchant/tests/dict_path_libenchant2.phpt @@ -0,0 +1,17 @@ +--TEST-- +enchant_broker_set_dict_path() / enchant_broker_get_dict_path() honour their return types without libenchant 1 support +--EXTENSIONS-- +enchant +--SKIPIF-- + +--FILE-- + +--EXPECT-- +bool(false) +bool(false)