From: Karel Zak Date: Thu, 27 Nov 2025 09:27:07 +0000 (+0100) Subject: lib, lscpu: fix const qualifier discarded warnings in bsearch X-Git-Tag: v2.41.3~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67fdcff1434fbe7f0faae892aa3e38ed2d13ad70;p=thirdparty%2Futil-linux.git lib, lscpu: fix const qualifier discarded warnings in bsearch Fix compilation warnings from newer compilers with stricter const-correctness checks. When bsearch() searches in const arrays, the result pointer must also be const to avoid discarding the const qualifier. Fixed in: - lib/color-names.c: searching in static const basic_schemes[] - sys-utils/lscpu-cputype.c: searching in const pattern arrays The warnings were: lib/color-names.c:62:13: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers] Signed-off-by: Karel Zak (cherry picked from commit 0cef3e4f5aac19bc3623883ca64c66538aa9b442) --- diff --git a/lib/color-names.c b/lib/color-names.c index 88c4ef957..daebcedae 100644 --- a/lib/color-names.c +++ b/lib/color-names.c @@ -54,7 +54,8 @@ const char *color_sequence_from_colorname(const char *str) { "white", UL_COLOR_WHITE }, { "yellow", UL_COLOR_BOLD_YELLOW } }; - struct ul_color_name key = { .name = str }, *res; + struct ul_color_name key = { .name = str }; + const struct ul_color_name *res; if (!str) return NULL; diff --git a/sys-utils/lscpu-cputype.c b/sys-utils/lscpu-cputype.c index 3937a00a8..99b112bf9 100644 --- a/sys-utils/lscpu-cputype.c +++ b/sys-utils/lscpu-cputype.c @@ -444,7 +444,8 @@ static char *key_cleanup(char *str, int *keynum) static const struct cpuinfo_pattern *cpuinfo_parse_line(char *str, char **value, int *keynum) { - struct cpuinfo_pattern key = { .id = 0 }, *pat; + struct cpuinfo_pattern key = { .id = 0 }; + const struct cpuinfo_pattern *pat; char *p, *v; char buf[CPUTYPE_PATTERN_BUFSZ] = { 0 };