Skip to content

Commit

Permalink
depmod: use uint8_t for the child prefix/index
Browse files Browse the repository at this point in the history
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 <[email protected]>
Link: #251
Signed-off-by: Lucas De Marchi <[email protected]>
  • Loading branch information
evelikov authored and lucasdemarchi committed Nov 22, 2024
1 parent 3f8f288 commit f5589e7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tools/depmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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:"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f5589e7

Please sign in to comment.