Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang UBSan fixes #2692

Closed
wants to merge 16 commits into from
Closed
5 changes: 3 additions & 2 deletions libdispatch/ncexhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,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 @@ -854,7 +854,8 @@ 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
5 changes: 3 additions & 2 deletions libdispatch/utf8proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,13 @@ static nc_utf8proc_ssize_t nc_seqindex_write_char_decomposed(nc_utf8proc_uint16_
nc_utf8proc_ssize_t written = 0;
const nc_utf8proc_uint16_t *entry = &nc_utf8proc_sequences[seqindex & 0x1FFF];
int len = seqindex >> 13;
assert(dst != NULL);
if (len >= 7) {
len = *entry;
entry++;
}
for (; len >= 0; entry++, len--) {
nc_utf8proc_int32_t entry_cp = nc_seqindex_decode_entry(&entry);

written += nc_utf8proc_decompose_char(entry_cp, dst+written,
(bufsize > written) ? (bufsize - written) : 0, options,
last_boundclass);
Expand Down Expand Up @@ -499,6 +499,7 @@ static nc_utf8proc_ssize_t nc_seqindex_write_char_decomposed(nc_utf8proc_uint16_
) {
/* strlen will be ignored, if UTF8PROC_NULLTERM is set in options */
nc_utf8proc_ssize_t wpos = 0;
assert(buffer != NULL);
if ((options & UTF8PROC_COMPOSE) && (options & UTF8PROC_DECOMPOSE))
return UTF8PROC_ERROR_INVALIDOPTS;
if ((options & UTF8PROC_STRIPMARK) &&
Expand Down Expand Up @@ -526,7 +527,7 @@ static nc_utf8proc_ssize_t nc_seqindex_write_char_decomposed(nc_utf8proc_uint16_
uc = custom_func(uc, custom_data); /* user-specified custom mapping */
}
decomp_result = nc_utf8proc_decompose_char(
uc, buffer + wpos, (bufsize > wpos) ? (bufsize - wpos) : 0, options,
uc, buffer+wpos, (bufsize > wpos) ? (bufsize - wpos) : 0, options,
&boundclass
);
if (decomp_result < 0) return decomp_result;
Expand Down
1 change: 1 addition & 0 deletions libdispatch/utf8proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
/** @} */

#include <stdlib.h>
#include <assert.h>
#include "ncexternl.h"

#if defined(_MSC_VER) && _MSC_VER < 1800
Expand Down
1 change: 1 addition & 0 deletions libsrc/attr.m4
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ dup_NC_attrarrayV(NC_attrarray *ncap, const NC_attrarray *ref)
ncap->nelems = 0;
{
NC_attr **app = ncap->value;
assert(app != NULL);
const NC_attr **drpp = (const NC_attr **)ref->value;
NC_attr *const *const end = &app[ref->nelems];
for( /*NADA*/; app < end; drpp++, app++, ncap->nelems++)
Expand Down
1 change: 1 addition & 0 deletions libsrc/dim.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ dup_NC_dimarrayV(NC_dimarray *ncap, const NC_dimarray *ref)
{
NC_dim **dpp = ncap->value;
const NC_dim **drpp = (const NC_dim **)ref->value;
assert(dpp != NULL);
NC_dim *const *const end = &dpp[ref->nelems];
for( /*NADA*/; dpp < end; drpp++, dpp++, ncap->nelems++)
{
Expand Down
4 changes: 2 additions & 2 deletions libsrc/nc3internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,10 +950,10 @@ int
NC_calcsize(const NC3_INFO *ncp, off_t *calcsizep)
{
NC_var **vpp = (NC_var **)ncp->vars.value;
NC_var *const *const end = &vpp[ncp->vars.nelems];
NC_var *const *const end = vpp ? &vpp[ncp->vars.nelems] : NULL;
NC_var *last_fix = NULL; /* last "non-record" var */
int numrecvars = 0; /* number of record variables */

if(ncp->vars.nelems == 0) { /* no non-record variables and
no record variables */
*calcsizep = ncp->xsz; /* size of header */
Expand Down
Loading
Loading