]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
depmod: use uint8_t for the child prefix/index
authorEmil Velikov <emil.l.velikov@gmail.com>
Sat, 16 Nov 2024 15:20:42 +0000 (15:20 +0000)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 22 Nov 2024 21:31:15 +0000 (15:31 -0600)
Stop implicitly casting the child prefix/index to int. It can have high
bits set thus get promoted to wildly incorrect value and cause chaos
further on.

In addition, convert the existing `unsigned char` instances to uint8_t,
which better illustrates what we're after - a fixed sized 8 bit unsigned
integer.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/251
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
tools/depmod.c

index fbac8d60915d2cbd0c35449c2cffc71dd1083aa9..0126124260a02344725d10d4a8da5977b8bf2ac6 100644 (file)
@@ -134,8 +134,8 @@ struct index_value {
 struct index_node {
        char *prefix; /* path compression */
        struct index_value *values;
-       unsigned char first; /* range of child nodes */
-       unsigned char last;
+       uint8_t first; /* range of child nodes */
+       uint8_t last;
        uint32_t size; /* size of node */
        uint32_t total; /* size of node and its children */
        struct index_node *children[INDEX_CHILDMAX]; /* indexed by character */
@@ -206,7 +206,7 @@ static void index__checkstring(const char *str)
        int i;
 
        for (i = 0; str[i]; i++) {
-               unsigned char ch = (unsigned char)str[i];
+               uint8_t ch = (uint8_t)str[i];
 
                if (ch >= INDEX_CHILDMAX)
                        CRIT("Module index: bad character '%c'=0x%x - only 7-bit ASCII is supported:"
@@ -248,7 +248,7 @@ static int index_insert(struct index_node *node, const char *key, const char *va
                        unsigned int priority)
 {
        int i = 0; /* index within str */
-       int ch;
+       uint8_t ch;
 
        index__checkstring(key);
        index__checkstring(value);
@@ -346,7 +346,7 @@ static uint32_t index_calculate_size(struct index_node *node)
        if (index__haschildren(node)) {
                int i;
 
-               node->size += 2; /* first + last, unsigned char */
+               node->size += 2; /* first + last, uint8_t */
                node->size += (node->last - node->first + 1) * sizeof(uint32_t);
 
                for (i = node->first; i <= node->last; i++) {
@@ -556,7 +556,7 @@ static int cfg_search_add(struct cfg *cfg, const char *path)
                memcpy(s->path, path, len);
        }
 
-       DBG("search add: %s, search type=%hhu\n", path, (unsigned char)type);
+       DBG("search add: %s, search type=%hhu\n", path, (uint8_t)type);
 
        s->next = cfg->searches;
        cfg->searches = s;