From 4d198a2e77ce90016e7d27b2816c8845ab173487 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Sun, 30 Apr 2023 18:00:35 -0400 Subject: [PATCH 01/15] Fixed misaligned memory access flagged by UBSan Use memcpy to copy correctly even for unaligned memory. This was already done for some functions here, but not all. Also took the oppurtunity to remove a bunch of seemingly obsolete/commented code. --- libsrc/ncx.m4 | 268 ++++---------------------------------------------- 1 file changed, 17 insertions(+), 251 deletions(-) diff --git a/libsrc/ncx.m4 b/libsrc/ncx.m4 index c8ea6df416..a9fb11f41b 100644 --- a/libsrc/ncx.m4 +++ b/libsrc/ncx.m4 @@ -307,88 +307,24 @@ swapn2b(void *dst, const void *src, IntType nn) IntType i; uint16_t *op = (uint16_t*) dst; uint16_t *ip = (uint16_t*) src; + uint16_t tmp; for (i=0; i 0) - * { - * *op++ = *(++ip); - * *op++ = *(ip++ -1); - * } - */ - while (nn > 3) - { - *op++ = *(++ip); - *op++ = *(ip++ -1); - *op++ = *(++ip); - *op++ = *(ip++ -1); - *op++ = *(++ip); - *op++ = *(ip++ -1); - *op++ = *(++ip); - *op++ = *(ip++ -1); - nn -= 4; - } - while (nn-- > 0) - { - *op++ = *(++ip); - *op++ = *(ip++ -1); - } -#endif } # ifndef vax inline static void swap4b(void *dst, const void *src) { - /* copy over, make the below swap in-place */ uint32_t tmp; - /* use memcpy to avoid type punning */ + /* memcpy is used to handle the case of unaligned memory */ memcpy(&tmp, src, sizeof(tmp)); tmp = SWAP4(tmp); memcpy(dst, &tmp, 4); - - /* Codes below will cause "break strict-aliasing rules" in gcc - uint32_t *op = (uint32_t*)dst; - *op = *(uint32_t*)src; - *op = SWAP4(*op); - */ - - /* Below are copied from netCDF-4. - * See https://bugtracking.unidata.ucar.edu/browse/NCF-338 - * Quote "One issue we are wrestling with is how compilers optimize this - * code. For some reason, we are actually needing to add an artificial - * move to a 4 byte space to get it to work. I think what is happening is - * that the optimizer is bit shifting within a double, which is incorrect. - * The following code actually does work correctly. - * This is in Linux land, gcc. - * - * However, the above in-place byte-swap does not appear affected by this. - */ -#if 0 - uint32_t *ip = (uint32_t*)src; - uint32_t tempOut; /* cannot use pointer when gcc O2 optimizer is used */ - tempOut = SWAP4(*ip); - - *(float *)dst = *(float *)(&tempOut); -#endif - - /* OLD implementation that results in four load and four store CPU - instructions - char *op = dst; - const char *ip = src; - op[0] = ip[3]; - op[1] = ip[2]; - op[2] = ip[1]; - op[3] = ip[0]; - */ - } # endif /* !vax */ @@ -398,110 +334,24 @@ swapn4b(void *dst, const void *src, IntType nn) IntType i; uint32_t *op = (uint32_t*) dst; uint32_t *ip = (uint32_t*) src; + uint32_t tmp; for (i=0; i 0) - * { - * op[0] = ip[3]; - * op[1] = ip[2]; - * op[2] = ip[1]; - * op[3] = ip[0]; - * op += 4; - * ip += 4; - * } - */ - while (nn > 3) - { - op[0] = ip[3]; - op[1] = ip[2]; - op[2] = ip[1]; - op[3] = ip[0]; - op[4] = ip[7]; - op[5] = ip[6]; - op[6] = ip[5]; - op[7] = ip[4]; - op[8] = ip[11]; - op[9] = ip[10]; - op[10] = ip[9]; - op[11] = ip[8]; - op[12] = ip[15]; - op[13] = ip[14]; - op[14] = ip[13]; - op[15] = ip[12]; - op += 16; - ip += 16; - nn -= 4; - } - while (nn-- > 0) - { - op[0] = ip[3]; - op[1] = ip[2]; - op[2] = ip[1]; - op[3] = ip[0]; - op += 4; - ip += 4; - } -#endif } # ifndef vax inline static void swap8b(void *dst, const void *src) { -#ifdef FLOAT_WORDS_BIGENDIAN - /* copy over, make the below swap in-place */ - *(uint64_t*)dst = *(uint64_t*)src; - - uint32_t *op = (uint32_t*)dst; - *op = SWAP4(*op); - op = (uint32_t*)((char*)dst+4); - *op = SWAP4(*op); -#else uint64_t tmp; - /* use memcpy to avoid type punning */ + /* memcpy is used to handle the case of unaligned memory */ memcpy(&tmp, src, sizeof(tmp)); tmp = SWAP8(tmp); memcpy(dst, &tmp, 8); - - /* Codes below will cause "break strict-aliasing rules" in gcc - uint64_t *op = (uint64_t*)dst; - *op = *(uint64_t*)src; - *op = SWAP8(*op); - */ -#endif - -#if 0 - char *op = dst; - const char *ip = src; -# ifndef FLOAT_WORDS_BIGENDIAN - op[0] = ip[7]; - op[1] = ip[6]; - op[2] = ip[5]; - op[3] = ip[4]; - op[4] = ip[3]; - op[5] = ip[2]; - op[6] = ip[1]; - op[7] = ip[0]; -# else - op[0] = ip[3]; - op[1] = ip[2]; - op[2] = ip[1]; - op[3] = ip[0]; - op[4] = ip[7]; - op[5] = ip[6]; - op[6] = ip[5]; - op[7] = ip[4]; -#endif -#endif } # endif /* !vax */ @@ -509,100 +359,16 @@ swap8b(void *dst, const void *src) inline static void swapn8b(void *dst, const void *src, IntType nn) { -#ifdef FLOAT_WORDS_BIGENDIAN - IntType i; - uint64_t *dst_p = (uint64_t*) dst; - uint64_t *src_p = (uint64_t*) src; - for (i=0; i 0) - * { - * op[0] = ip[7]; - * op[1] = ip[6]; - * op[2] = ip[5]; - * op[3] = ip[4]; - * op[4] = ip[3]; - * op[5] = ip[2]; - * op[6] = ip[1]; - * op[7] = ip[0]; - * op += 8; - * ip += 8; - * } - */ -# ifndef FLOAT_WORDS_BIGENDIAN - while (nn > 1) - { - op[0] = ip[7]; - op[1] = ip[6]; - op[2] = ip[5]; - op[3] = ip[4]; - op[4] = ip[3]; - op[5] = ip[2]; - op[6] = ip[1]; - op[7] = ip[0]; - op[8] = ip[15]; - op[9] = ip[14]; - op[10] = ip[13]; - op[11] = ip[12]; - op[12] = ip[11]; - op[13] = ip[10]; - op[14] = ip[9]; - op[15] = ip[8]; - op += 16; - ip += 16; - nn -= 2; - } - while (nn-- > 0) - { - op[0] = ip[7]; - op[1] = ip[6]; - op[2] = ip[5]; - op[3] = ip[4]; - op[4] = ip[3]; - op[5] = ip[2]; - op[6] = ip[1]; - op[7] = ip[0]; - op += 8; - ip += 8; - } -# else - while (nn-- > 0) - { - op[0] = ip[3]; - op[1] = ip[2]; - op[2] = ip[1]; - op[3] = ip[0]; - op[4] = ip[7]; - op[5] = ip[6]; - op[6] = ip[5]; - op[7] = ip[4]; - op += 8; - ip += 8; - } -#endif -#endif } # endif /* !vax */ From 81954c8e25596c76a17bfbf020dfee0a35d95bda Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Mon, 1 May 2023 13:25:53 -0400 Subject: [PATCH 02/15] 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. --- libdispatch/ncexhash.c | 4 ++-- libdispatch/nclistmgr.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libdispatch/ncexhash.c b/libdispatch/ncexhash.c index dcaa919dca..536841e439 100644 --- a/libdispatch/ncexhash.c +++ b/libdispatch/ncexhash.c @@ -110,7 +110,7 @@ ncexinit(void) int i; bitmasks[0] = 0; for(i=1;ileaflen, 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", diff --git a/libdispatch/nclistmgr.c b/libdispatch/nclistmgr.c index 48b4eeb584..6b2b90a478 100644 --- a/libdispatch/nclistmgr.c +++ b/libdispatch/nclistmgr.c @@ -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; From a384482f63649a894ba0245a0caf04ff4ef3d0fe Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Mon, 1 May 2023 13:26:58 -0400 Subject: [PATCH 03/15] Fixed various UBSan warnings about working with NULL pointers Any pointer arithmetic with NULL pointers is technically UB, even if you don't end up dereferencing the pointer. --- libdispatch/utf8proc.c | 7 +++++-- libsrc/attr.m4 | 2 +- libsrc/dim.c | 2 +- libsrc/nc3internal.c | 2 +- libsrc/putget.m4 | 2 +- libsrc/v1hpg.c | 26 +++++++++++++++----------- libsrc/var.c | 2 +- 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/libdispatch/utf8proc.c b/libdispatch/utf8proc.c index 3a05dd3b34..00dfc65820 100644 --- a/libdispatch/utf8proc.c +++ b/libdispatch/utf8proc.c @@ -355,7 +355,8 @@ static nc_utf8proc_ssize_t nc_seqindex_write_char_decomposed(nc_utf8proc_uint16_ 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, + nc_utf8proc_int32_t *dest = dst ? (dst+written) : NULL; + written += nc_utf8proc_decompose_char(entry_cp, dest, (bufsize > written) ? (bufsize - written) : 0, options, last_boundclass); if (written < 0) return UTF8PROC_ERROR_OVERFLOW; @@ -525,8 +526,10 @@ static nc_utf8proc_ssize_t nc_seqindex_write_char_decomposed(nc_utf8proc_uint16_ if (custom_func != NULL) { uc = custom_func(uc, custom_data); /* user-specified custom mapping */ } + nc_utf8proc_int32_t *dst = NULL; + if (buffer) dst = buffer + wpos; decomp_result = nc_utf8proc_decompose_char( - uc, buffer + wpos, (bufsize > wpos) ? (bufsize - wpos) : 0, options, + uc, dst, (bufsize > wpos) ? (bufsize - wpos) : 0, options, &boundclass ); if (decomp_result < 0) return decomp_result; diff --git a/libsrc/attr.m4 b/libsrc/attr.m4 index 94bebf2386..2f392c991c 100644 --- a/libsrc/attr.m4 +++ b/libsrc/attr.m4 @@ -231,7 +231,7 @@ dup_NC_attrarrayV(NC_attrarray *ncap, const NC_attrarray *ref) { NC_attr **app = ncap->value; const NC_attr **drpp = (const NC_attr **)ref->value; - NC_attr *const *const end = &app[ref->nelems]; + NC_attr *const *const end = app ? &app[ref->nelems] : NULL; for( /*NADA*/; app < end; drpp++, app++, ncap->nelems++) { *app = dup_NC_attr(*drpp); diff --git a/libsrc/dim.c b/libsrc/dim.c index 227ac5ab5c..edcd2f8ccb 100644 --- a/libsrc/dim.c +++ b/libsrc/dim.c @@ -229,7 +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; - NC_dim *const *const end = &dpp[ref->nelems]; + NC_dim *const *const end = dpp ? &dpp[ref->nelems] : NULL; for( /*NADA*/; dpp < end; drpp++, dpp++, ncap->nelems++) { *dpp = dup_NC_dim(*drpp); diff --git a/libsrc/nc3internal.c b/libsrc/nc3internal.c index 2045304e05..76b4cfb8fc 100644 --- a/libsrc/nc3internal.c +++ b/libsrc/nc3internal.c @@ -950,7 +950,7 @@ 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 */ diff --git a/libsrc/putget.m4 b/libsrc/putget.m4 index 2779480bab..9a0aca8a27 100644 --- a/libsrc/putget.m4 +++ b/libsrc/putget.m4 @@ -551,7 +551,7 @@ static int NCedgeck(const NC3_INFO* ncp, const NC_var *varp, const size_t *start, const size_t *edges) { - const size_t *const end = start + varp->ndims; + const size_t *const end = start ? (start + varp->ndims) : NULL; const size_t *shp = varp->shape; if(varp->ndims == 0) diff --git a/libsrc/v1hpg.c b/libsrc/v1hpg.c index 63172f2274..68ea7f897f 100644 --- a/libsrc/v1hpg.c +++ b/libsrc/v1hpg.c @@ -448,7 +448,7 @@ ncx_len_NC_dimarray(const NC_dimarray *ncap, int version) /* else */ { const NC_dim **dpp = (const NC_dim **)ncap->value; - const NC_dim *const *const end = &dpp[ncap->nelems]; + const NC_dim *const *const end = dpp ? &dpp[ncap->nelems] : NULL; for( /*NADA*/; dpp < end; dpp++) { xlen += ncx_len_NC_dim(*dpp,version); @@ -641,11 +641,13 @@ v1h_put_NC_attrV(v1hs *psp, const NC_attr *attrp) if(status != NC_NOERR) return status; - (void) memcpy(psp->pos, value, nbytes); - + if (value) { + (void) memcpy(psp->pos, value, nbytes); + value = (void *)((char *)value + nbytes); + } + psp->pos = (void *)((char *)psp->pos + nbytes); - value = (void *)((char *)value + nbytes); - remaining -= nbytes; + remaining -= nbytes; } while(remaining != 0); @@ -709,11 +711,13 @@ v1h_get_NC_attrV(v1hs *gsp, NC_attr *attrp) if(status != NC_NOERR) return status; - (void) memcpy(value, gsp->pos, nget); + if (value) { + (void) memcpy(value, gsp->pos, nget); + value = (void *)((signed char *)value + nget); + } + gsp->pos = (void*)((unsigned char *)gsp->pos + nget); - value = (void *)((signed char *)value + nget); - remaining -= nget; } while(remaining != 0); @@ -790,7 +794,7 @@ ncx_len_NC_attrarray(const NC_attrarray *ncap, int version) /* else */ { const NC_attr **app = (const NC_attr **)ncap->value; - const NC_attr *const *const end = &app[ncap->nelems]; + const NC_attr *const *const end = app ? &app[ncap->nelems] : NULL; for( /*NADA*/; app < end; app++) { xlen += ncx_len_NC_attr(*app,version); @@ -1090,7 +1094,7 @@ ncx_len_NC_vararray(const NC_vararray *ncap, size_t sizeof_off_t, int version) /* else */ { const NC_var **vpp = (const NC_var **)ncap->value; - const NC_var *const *const end = &vpp[ncap->nelems]; + const NC_var *const *const end = vpp ? &vpp[ncap->nelems] : NULL; for( /*NADA*/; vpp < end; vpp++) { xlen += ncx_len_NC_var(*vpp, sizeof_off_t, version); @@ -1224,7 +1228,7 @@ static int NC_computeshapes(NC3_INFO* ncp) { 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 *first_var = NULL; /* first "non-record" var */ NC_var *first_rec = NULL; /* first "record" var */ int status; diff --git a/libsrc/var.c b/libsrc/var.c index f09bbe27bd..5604324de9 100644 --- a/libsrc/var.c +++ b/libsrc/var.c @@ -267,7 +267,7 @@ dup_NC_vararrayV(NC_vararray *ncap, const NC_vararray *ref) { NC_var **vpp = ncap->value; const NC_var **drpp = (const NC_var **)ref->value; - NC_var *const *const end = &vpp[ref->nelems]; + NC_var *const *const end = vpp ? &vpp[ref->nelems] : NULL; for( /*NADA*/; vpp < end; drpp++, vpp++, ncap->nelems++) { *vpp = dup_NC_var(*drpp); From 3f048ed285c80702b39b1347e741f98cd3a76aae Mon Sep 17 00:00:00 2001 From: Dennis Heimbigner Date: Sat, 3 Jun 2023 12:38:56 -0600 Subject: [PATCH 04/15] Update ncexhash.c I think this is the right expression --- libdispatch/ncexhash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdispatch/ncexhash.c b/libdispatch/ncexhash.c index 536841e439..40518a0369 100644 --- a/libdispatch/ncexhash.c +++ b/libdispatch/ncexhash.c @@ -854,7 +854,7 @@ ncexhashprintstats(NCexhashmap* map) fprintf(stderr," |leaf|=%d nactive/nleaves=%g", map->leaflen, leafavg); fprintf(stderr," load=%g",leafload); fprintf(stderr,"]\n"); - dirsize = (1ULL<<(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", From bf58ab33b18920406ec026ad2d3d6d0601cb09be Mon Sep 17 00:00:00 2001 From: Dennis Heimbigner Date: Sat, 3 Jun 2023 12:43:33 -0600 Subject: [PATCH 05/15] Update utf8proc.c Change null dst handling --- libdispatch/utf8proc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libdispatch/utf8proc.c b/libdispatch/utf8proc.c index 00dfc65820..93a852a8e0 100644 --- a/libdispatch/utf8proc.c +++ b/libdispatch/utf8proc.c @@ -348,15 +348,14 @@ 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; + if(dst == NULL) return written; if (len >= 7) { len = *entry; entry++; } for (; len >= 0; entry++, len--) { nc_utf8proc_int32_t entry_cp = nc_seqindex_decode_entry(&entry); - - nc_utf8proc_int32_t *dest = dst ? (dst+written) : NULL; - written += nc_utf8proc_decompose_char(entry_cp, dest, + written += nc_utf8proc_decompose_char(entry_cp, dst+written, (bufsize > written) ? (bufsize - written) : 0, options, last_boundclass); if (written < 0) return UTF8PROC_ERROR_OVERFLOW; From e4ab00347c37b2897d907dfbd16ab0ae968c962e Mon Sep 17 00:00:00 2001 From: Dennis Heimbigner Date: Sat, 3 Jun 2023 12:51:59 -0600 Subject: [PATCH 06/15] Update utf8proc.c Handle buffer == NULL --- libdispatch/utf8proc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libdispatch/utf8proc.c b/libdispatch/utf8proc.c index 93a852a8e0..05973dd7c3 100644 --- a/libdispatch/utf8proc.c +++ b/libdispatch/utf8proc.c @@ -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; + if(buffer == NULL) return wpos; if ((options & UTF8PROC_COMPOSE) && (options & UTF8PROC_DECOMPOSE)) return UTF8PROC_ERROR_INVALIDOPTS; if ((options & UTF8PROC_STRIPMARK) && @@ -525,10 +526,8 @@ static nc_utf8proc_ssize_t nc_seqindex_write_char_decomposed(nc_utf8proc_uint16_ if (custom_func != NULL) { uc = custom_func(uc, custom_data); /* user-specified custom mapping */ } - nc_utf8proc_int32_t *dst = NULL; - if (buffer) dst = buffer + wpos; decomp_result = nc_utf8proc_decompose_char( - uc, dst, (bufsize > wpos) ? (bufsize - wpos) : 0, options, + uc, buffer+wpos, (bufsize > wpos) ? (bufsize - wpos) : 0, options, &boundclass ); if (decomp_result < 0) return decomp_result; From baeb5cd08eef15a67a298b0553e78709bd17c641 Mon Sep 17 00:00:00 2001 From: Dennis Heimbigner Date: Sat, 3 Jun 2023 12:57:15 -0600 Subject: [PATCH 07/15] Update attr.m4 Handle null app case --- libsrc/attr.m4 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libsrc/attr.m4 b/libsrc/attr.m4 index 2f392c991c..d9a0405b3b 100644 --- a/libsrc/attr.m4 +++ b/libsrc/attr.m4 @@ -230,8 +230,9 @@ dup_NC_attrarrayV(NC_attrarray *ncap, const NC_attrarray *ref) ncap->nelems = 0; { NC_attr **app = ncap->value; + if(app != NULL) { const NC_attr **drpp = (const NC_attr **)ref->value; - NC_attr *const *const end = app ? &app[ref->nelems] : NULL; + NC_attr *const *const end = &app[ref->nelems]; for( /*NADA*/; app < end; drpp++, app++, ncap->nelems++) { *app = dup_NC_attr(*drpp); @@ -241,6 +242,7 @@ dup_NC_attrarrayV(NC_attrarray *ncap, const NC_attrarray *ref) break; } } + } } if(status != NC_NOERR) From ba1b41d7910a766f58827f5508416eada3601ab3 Mon Sep 17 00:00:00 2001 From: Dennis Heimbigner Date: Sat, 3 Jun 2023 12:59:27 -0600 Subject: [PATCH 08/15] Update dim.c Handle null case --- libsrc/dim.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libsrc/dim.c b/libsrc/dim.c index edcd2f8ccb..0dab8f096b 100644 --- a/libsrc/dim.c +++ b/libsrc/dim.c @@ -229,7 +229,8 @@ dup_NC_dimarrayV(NC_dimarray *ncap, const NC_dimarray *ref) { NC_dim **dpp = ncap->value; const NC_dim **drpp = (const NC_dim **)ref->value; - NC_dim *const *const end = dpp ? &dpp[ref->nelems] : NULL; + if(dpp != NULL) { + NC_dim *const *const end = &dpp[ref->nelems]; for( /*NADA*/; dpp < end; drpp++, dpp++, ncap->nelems++) { *dpp = dup_NC_dim(*drpp); @@ -239,6 +240,7 @@ dup_NC_dimarrayV(NC_dimarray *ncap, const NC_dimarray *ref) break; } } + } } if(status != NC_NOERR) From 042bc28cdad6cce13ea06404f61906b41186e950 Mon Sep 17 00:00:00 2001 From: Dennis Heimbigner Date: Sat, 3 Jun 2023 13:13:12 -0600 Subject: [PATCH 09/15] Update utf8proc.c catch error case --- libdispatch/utf8proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdispatch/utf8proc.c b/libdispatch/utf8proc.c index 05973dd7c3..de068b1441 100644 --- a/libdispatch/utf8proc.c +++ b/libdispatch/utf8proc.c @@ -499,7 +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; - if(buffer == NULL) return wpos; + assert(buffer != NULL); if ((options & UTF8PROC_COMPOSE) && (options & UTF8PROC_DECOMPOSE)) return UTF8PROC_ERROR_INVALIDOPTS; if ((options & UTF8PROC_STRIPMARK) && From c895410531bb111fe068885f2697efcf9c29dab7 Mon Sep 17 00:00:00 2001 From: Dennis Heimbigner Date: Sat, 3 Jun 2023 13:14:34 -0600 Subject: [PATCH 10/15] Update utf8proc.c throw error --- libdispatch/utf8proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdispatch/utf8proc.c b/libdispatch/utf8proc.c index de068b1441..b5add8da75 100644 --- a/libdispatch/utf8proc.c +++ b/libdispatch/utf8proc.c @@ -348,7 +348,7 @@ 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; - if(dst == NULL) return written; + assert(dst != NULL); if (len >= 7) { len = *entry; entry++; From 985ccbb9fdcd67ab6dc27e2de385193aec62a4e8 Mon Sep 17 00:00:00 2001 From: Dennis Heimbigner Date: Sat, 3 Jun 2023 13:16:32 -0600 Subject: [PATCH 11/15] Update attr.m4 catch error --- libsrc/attr.m4 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libsrc/attr.m4 b/libsrc/attr.m4 index d9a0405b3b..c315fd8a84 100644 --- a/libsrc/attr.m4 +++ b/libsrc/attr.m4 @@ -230,7 +230,7 @@ dup_NC_attrarrayV(NC_attrarray *ncap, const NC_attrarray *ref) ncap->nelems = 0; { NC_attr **app = ncap->value; - if(app != NULL) { + 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++) @@ -242,7 +242,6 @@ dup_NC_attrarrayV(NC_attrarray *ncap, const NC_attrarray *ref) break; } } - } } if(status != NC_NOERR) From d257dbb644698a4916f78e363b3dfff28060efd0 Mon Sep 17 00:00:00 2001 From: Dennis Heimbigner Date: Sat, 3 Jun 2023 13:17:44 -0600 Subject: [PATCH 12/15] Update dim.c catch error --- libsrc/dim.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libsrc/dim.c b/libsrc/dim.c index 0dab8f096b..da210fd531 100644 --- a/libsrc/dim.c +++ b/libsrc/dim.c @@ -229,7 +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; - if(dpp != NULL) { + assert(dpp != NULL); NC_dim *const *const end = &dpp[ref->nelems]; for( /*NADA*/; dpp < end; drpp++, dpp++, ncap->nelems++) { @@ -240,7 +240,6 @@ dup_NC_dimarrayV(NC_dimarray *ncap, const NC_dimarray *ref) break; } } - } } if(status != NC_NOERR) From 2f6e620c67b326110fb59d603301d9374f71d830 Mon Sep 17 00:00:00 2001 From: Dennis Heimbigner Date: Sat, 3 Jun 2023 13:19:40 -0600 Subject: [PATCH 13/15] Update nc3internal.c catch error --- libsrc/nc3internal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libsrc/nc3internal.c b/libsrc/nc3internal.c index 76b4cfb8fc..1e8e637d63 100644 --- a/libsrc/nc3internal.c +++ b/libsrc/nc3internal.c @@ -950,10 +950,13 @@ int NC_calcsize(const NC3_INFO *ncp, off_t *calcsizep) { NC_var **vpp = (NC_var **)ncp->vars.value; - NC_var *const *const end = vpp ? &vpp[ncp->vars.nelems] : NULL; + NC_var *const *const end = NULL; NC_var *last_fix = NULL; /* last "non-record" var */ int numrecvars = 0; /* number of record variables */ + assert(vpp != NULL); + end = &vpp[ncp->vars.nelems]; + if(ncp->vars.nelems == 0) { /* no non-record variables and no record variables */ *calcsizep = ncp->xsz; /* size of header */ From b5710bda1093fc143be1128f4d27187b02dd7d24 Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Tue, 15 Aug 2023 14:08:54 -0600 Subject: [PATCH 14/15] Reverted an assignment ot a const variable after declaration. --- libdispatch/utf8proc.h | 1 + libsrc/nc3internal.c | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libdispatch/utf8proc.h b/libdispatch/utf8proc.h index a88c184a74..e6f62ecd84 100644 --- a/libdispatch/utf8proc.h +++ b/libdispatch/utf8proc.h @@ -77,6 +77,7 @@ /** @} */ #include +#include #include "ncexternl.h" #if defined(_MSC_VER) && _MSC_VER < 1800 diff --git a/libsrc/nc3internal.c b/libsrc/nc3internal.c index 1e8e637d63..60a4e21fb9 100644 --- a/libsrc/nc3internal.c +++ b/libsrc/nc3internal.c @@ -950,12 +950,9 @@ int NC_calcsize(const NC3_INFO *ncp, off_t *calcsizep) { NC_var **vpp = (NC_var **)ncp->vars.value; - NC_var *const *const end = NULL; + 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 */ - - assert(vpp != NULL); - end = &vpp[ncp->vars.nelems]; if(ncp->vars.nelems == 0) { /* no non-record variables and no record variables */ From 7934e7dd99b054a4043edf21b372dfc526aaed0e Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Thu, 12 Oct 2023 16:46:38 -0600 Subject: [PATCH 15/15] retrigger checks