Skip to content

Commit

Permalink
prevent to cast from pointer to uint64 directly
Browse files Browse the repository at this point in the history
It is unsafe, especially, sizeof(void*) < sizeof(uint64_t).
Change to cast through uintptr_t instead.

Signed-off-by: OBATA Akio <obache@outlook.com>
  • Loading branch information
obache committed Oct 17, 2023
1 parent ef6fe77 commit 02f6570
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions imap/search_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ static int maxcost(const search_expr_t *e, hashu64_table *costcache)
if (!e) return 0;

if (costcache) {
intptr_t cost = (intptr_t) hashu64_lookup((uint64_t) e, costcache);
intptr_t cost = (intptr_t) hashu64_lookup((uint64_t)(uintptr_t) e, costcache);
assert(cost > INT_MIN && cost < INT_MAX);
if (cost) return cost > 0 ? cost : 0;
}
Expand All @@ -805,7 +805,7 @@ static int maxcost(const search_expr_t *e, hashu64_table *costcache)
}

if (costcache) {
hashu64_insert((uint64_t) e, (void*)((intptr_t)(cost ? cost : -1)), costcache);
hashu64_insert((uint64_t)(uintptr_t) e, (void*)((intptr_t)(cost ? cost : -1)), costcache);
}
return cost;
}
Expand Down

0 comments on commit 02f6570

Please sign in to comment.