Skip to content

Commit

Permalink
Eliminate 'cast truncates constant' MSVC warning in GC_add_map_entry
Browse files Browse the repository at this point in the history
(fix of commits 57ccbcc, 460b296)

* obj_map.c [!MARK_BIT_PER_OBJ] (GC_add_map_entry): Change
(hb_map_entry_t)~0U to
~(size_t)0>>((sizeof(size_t)-sizeof(hb_map_entry_t))*8) in static
assert; add comment.
  • Loading branch information
ivmai committed Sep 25, 2024
1 parent 82cd67b commit 1133dc4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion obj_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ GC_INNER void GC_register_displacement_inner(size_t offset)
hb_map_entry_t *new_map;

GC_ASSERT(I_HOLD_LOCK());
GC_STATIC_ASSERT(MAXOBJGRANULES - 1 <= (size_t)(hb_map_entry_t)~0U);
/* Ensure displ % lg fits into hb_map_entry_t. Note: the maximum */
/* value is computed in this way to avoid compiler complains about */
/* constant truncation or expression overflow. */
GC_STATIC_ASSERT(MAXOBJGRANULES - 1
<= ~(size_t)0 >> ((sizeof(size_t) - sizeof(hb_map_entry_t)) * 8));

if (lg > MAXOBJGRANULES) lg = 0;
if (EXPECT(GC_obj_map[lg] != NULL, TRUE)) return TRUE;

Expand Down

0 comments on commit 1133dc4

Please sign in to comment.