From: Emil Velikov Date: Wed, 9 Oct 2024 15:26:25 +0000 (+0100) Subject: libkmod: used unsigned type for INDEX_CHILDMAX and co X-Git-Tag: v34~242 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6b2653a35ea69e9f3e6804d0e6321ab211d523c6;p=thirdparty%2Fkmod.git libkmod: used unsigned type for INDEX_CHILDMAX and co Currently the define is an signed int of 128, which we store in a char triggering a clang warning. This is expected since the sign of char is platform specific. Convert the macro to unsigned and the respective variables to unsigned char, alongside the documentation comment. With that done, adjust the first/last checks so we don't get tautological-compare warnings from clang. Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/180 Signed-off-by: Lucas De Marchi --- diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index 6fe019ae..f047abfc 100644 --- a/libkmod/libkmod-index.c +++ b/libkmod/libkmod-index.c @@ -44,7 +44,7 @@ * where the keys in the index are treated as patterns. * This feature is required for module aliases. */ -#define INDEX_CHILDMAX 128 +#define INDEX_CHILDMAX 128u /* Disk format: * @@ -56,8 +56,8 @@ * * char[] prefix; // nul terminated * - * char first; - * char last; + * unsigned char first; + * unsigned char last; * uint32_t children[last - first + 1]; * * uint32_t value_count; @@ -677,7 +677,7 @@ static struct index_mm_node *index_mm_read_node(struct index_mm *idx, uint32_t o const char *prefix; int i, child_count, value_count, children_padding; uint32_t children[INDEX_CHILDMAX]; - char first, last; + unsigned char first, last; if ((offset & INDEX_NODE_MASK) == 0) return NULL; @@ -694,7 +694,7 @@ static struct index_mm_node *index_mm_read_node(struct index_mm *idx, uint32_t o first = read_char_mm(&p); last = read_char_mm(&p); - if (first > last || first < 0 || last < 0) + if (first > last || first >= INDEX_CHILDMAX || last >= INDEX_CHILDMAX) return NULL; child_count = last - first + 1;