]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib, lscpu: fix const qualifier discarded warnings in bsearch
authorKarel Zak <kzak@redhat.com>
Thu, 27 Nov 2025 09:27:07 +0000 (10:27 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 27 Nov 2025 09:27:07 +0000 (10:27 +0100)
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 <kzak@redhat.com>
lib/color-names.c
sys-utils/lscpu-cputype.c

index 88c4ef957747775ada6461e404bb2825b5435c4c..daebcedaef5938044777980c643640fdd1078536 100644 (file)
@@ -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;
index eda6bd1004b0899c9b8ceb03abd0803571c09d20..958cbe7b67c0833be4803ad070ce4d7a09e0453f 100644 (file)
@@ -450,7 +450,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 };