Fixed various UBSan warnings about invalid bit shifting

Just made sure to use unsigned, so that a bit does not get shifted into a sign bit.
This commit is contained in:
Sean McBride 2023-05-01 13:25:53 -04:00
parent 100dca4854
commit 1162f64d2a
2 changed files with 5 additions and 5 deletions

View File

@ -111,7 +111,7 @@ ncexinit(void)
int i; int i;
bitmasks[0] = 0; bitmasks[0] = 0;
for(i=1;i<NCEXHASHKEYBITS;i++) for(i=1;i<NCEXHASHKEYBITS;i++)
bitmasks[i] = (1 << i) - 1; bitmasks[i] = (1ULL << i) - 1;
ncexinitialized = 1; ncexinitialized = 1;
} }
@ -855,7 +855,7 @@ ncexhashprintstats(NCexhashmap* map)
fprintf(stderr," |leaf|=%d nactive/nleaves=%g", map->leaflen, leafavg); fprintf(stderr," |leaf|=%d nactive/nleaves=%g", map->leaflen, leafavg);
fprintf(stderr," load=%g",leafload); fprintf(stderr," load=%g",leafload);
fprintf(stderr,"]\n"); 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)); leafsize = (nleaves)*((unsigned long long)sizeof(NCexleaf));
total = dirsize + leafsize; total = dirsize + leafsize;
fprintf(stderr,"\tsizeof(directory)=%llu sizeof(leaves)=%lld total=%lld\n", fprintf(stderr,"\tsizeof(directory)=%llu sizeof(leaves)=%lld total=%lld\n",

View File

@ -81,8 +81,8 @@ free_NCList(void)
int int
add_to_NCList(NC* ncp) add_to_NCList(NC* ncp)
{ {
int i; unsigned int i;
int new_id; unsigned int new_id;
if(nc_filelist == NULL) { if(nc_filelist == NULL) {
if (!(nc_filelist = calloc(1, sizeof(NC*)*NCFILELISTLENGTH))) if (!(nc_filelist = calloc(1, sizeof(NC*)*NCFILELISTLENGTH)))
return NC_ENOMEM; return NC_ENOMEM;
@ -96,7 +96,7 @@ add_to_NCList(NC* ncp)
if(new_id == 0) return NC_ENOMEM; /* no more slots */ if(new_id == 0) return NC_ENOMEM; /* no more slots */
nc_filelist[new_id] = ncp; nc_filelist[new_id] = ncp;
numfiles++; numfiles++;
ncp->ext_ncid = (new_id << ID_SHIFT); ncp->ext_ncid = (int)(new_id << ID_SHIFT);
return NC_NOERR; return NC_NOERR;
} }