]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: used unsigned type for INDEX_CHILDMAX and co
authorEmil Velikov <emil.l.velikov@gmail.com>
Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 15 Oct 2024 18:37:11 +0000 (13:37 -0500)
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 <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/180
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-index.c

index 6fe019aeb5c6df27b94aa26de24fdaebd36b0b7b..f047abfc3ef0700db538c9d80f0964c8ecc02ca5 100644 (file)
@@ -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;