Skip to content

Commit

Permalink
Fixed various UBSan warnings about invalid bit shifting
Browse files Browse the repository at this point in the history
Just made sure to use unsigned, so that a bit does not get shifted into a sign bit.
  • Loading branch information
seanm committed Oct 31, 2023
1 parent 100dca4 commit 6151a0f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions libdispatch/ncexhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ ncexinit(void)
int i;
bitmasks[0] = 0;
for(i=1;i<NCEXHASHKEYBITS;i++)
bitmasks[i] = (1 << i) - 1;
bitmasks[i] = (1ULL << i) - 1;
ncexinitialized = 1;
}

Expand Down Expand Up @@ -855,7 +855,7 @@ ncexhashprintstats(NCexhashmap* map)
fprintf(stderr," |leaf|=%d nactive/nleaves=%g", map->leaflen, leafavg);
fprintf(stderr," load=%g",leafload);
fprintf(stderr,"]\n");
dirsize = (1<<(map->depth))*((unsigned long long)sizeof(void*));
dirsize = (1ULL<<(map->depth))*((unsigned long long)sizeof(void*));
leafsize = (nleaves)*((unsigned long long)sizeof(NCexleaf));
total = dirsize + leafsize;
fprintf(stderr,"\tsizeof(directory)=%llu sizeof(leaves)=%lld total=%lld\n",
Expand Down
4 changes: 2 additions & 2 deletions libdispatch/nclistmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ free_NCList(void)
int
add_to_NCList(NC* ncp)
{
int i;
int new_id;
unsigned int i;
unsigned int new_id;
if(nc_filelist == NULL) {
if (!(nc_filelist = calloc(1, sizeof(NC*)*NCFILELISTLENGTH)))
return NC_ENOMEM;
Expand Down

0 comments on commit 6151a0f

Please sign in to comment.