Pango 1.50.14 triggers a false positive "source object is likely at address zero" with GCC 13 (build failure) in pango-language.c
Originally described here => https://bugs.gentoo.org/903259
With GCC 13 I have a build failure:
In function ‘find_best_lang_match_cached’,
inlined from ‘find_best_lang_match_cached’ at ../pango-1.50.14/pango/pango-language.c:501:1,
inlined from ‘pango_language_get_scripts’ at ../pango-1.50.14/pango/pango-language.c:661:21:
../pango-1.50.14/pango/pango-language.c:518:12: error: array subscript 0 is outside array bounds of ‘const void *[0:]’ [-Werror=array-bounds=]
518 | *cache = result;
| ~~~~~~~^~~~~~~~
In function ‘pango_language_get_scripts’:
cc1: note: source object is likely at address zero
cc1: some warnings being treated as errors
To circumvent it, I tried to enclose the function find_best_lang_match_cached() in pango-language.c with #pragmas like this:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
static gconstpointer
find_best_lang_match_cached (PangoLanguage *language,
gconstpointer *cache,
gconstpointer records,
guint num_records,
guint record_size)
{
gconstpointer result;
if (G_LIKELY (cache && *cache != (gconstpointer) -1))
return *cache;
result = find_best_lang_match (language,
records,
num_records,
record_size);
if (cache)
*cache = result;
return result;
}
#pragma GCC diagnostic pop
Reading the code a bit, I do not see a reason to have a null-value for the pointer "result" but the compiler is not happy with the code :)