From a8494773f847671d7eaf633b990f04d6c17f18e3 Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Mon, 23 Feb 2015 13:38:18 -0700 Subject: [PATCH] Addressed an 'unallocated memory' warning generated by clang. --- libsrc/attr.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/libsrc/attr.c b/libsrc/attr.c index 96ecf9ca2..362ec5a13 100644 --- a/libsrc/attr.c +++ b/libsrc/attr.c @@ -115,7 +115,7 @@ new_NC_attr( free(name); if(strp == NULL) return NULL; - + attrp = new_x_NC_attr(strp, type, nelems); if(attrp == NULL) { @@ -134,7 +134,10 @@ dup_NC_attr(const NC_attr *rattrp) rattrp->type, rattrp->nelems); if(attrp == NULL) return NULL; - (void) memcpy(attrp->xvalue, rattrp->xvalue, rattrp->xsz); + if(attrp->xvalue == NULL) + attrp->xvalue = (void*)malloc(sizeof(void*)*rattrp->xsz); + + (void) memcpy(attrp->xvalue, rattrp->xvalue, rattrp->xsz); return attrp; } @@ -176,7 +179,7 @@ void free_NC_attrarrayV(NC_attrarray *ncap) { assert(ncap != NULL); - + if(ncap->nalloc == 0) return; @@ -265,7 +268,7 @@ incr_NC_attrarray(NC_attrarray *ncap, NC_attr *newelemp) (ncap->nalloc + NC_ARRAY_GROWBY) * sizeof(NC_attr *)); if(vp == NULL) return NC_ENOMEM; - + ncap->value = vp; ncap->nalloc += NC_ARRAY_GROWBY; } @@ -362,7 +365,7 @@ NC_findattr(const NC_attrarray *ncap, const char *uname) /* * Look up by ncid, varid and name, return NULL if not found */ -static int +static int NC_lookupattr(int ncid, int varid, const char *name, /* attribute name */ @@ -424,7 +427,7 @@ NC3_inq_attname(int ncid, int varid, int attnum, char *name) } -int +int NC3_inq_attid(int ncid, int varid, const char *name, int *attnump) { int status; @@ -441,7 +444,7 @@ NC3_inq_attid(int ncid, int varid, const char *name, int *attnump) ncap = NC_attrarray0(ncp, varid); if(ncap == NULL) return NC_ENOTVAR; - + attrpp = NC_findattr(ncap, name); if(attrpp == NULL) @@ -577,7 +580,7 @@ NC3_del_att(int ncid, int varid, const char *uname) char *name = (char *)utf8proc_NFC((const unsigned char *)uname); if(name == NULL) return NC_ENOMEM; - + /* sortof inline NC_findattr() */ slen = strlen(name); @@ -1399,10 +1402,10 @@ NC3_put_att( if(!NC_indef(ncp)) { const size_t xsz = ncx_len_NC_attrV(type, nelems); attrp = *attrpp; /* convenience */ - + if(xsz > attrp->xsz) return NC_ENOTINDEFINE; /* else, we can reuse existing without redef */ - + attrp->xsz = xsz; attrp->type = type; attrp->nelems = nelems; @@ -1411,7 +1414,7 @@ NC3_put_att( void *xp = attrp->xvalue; status = dispatchput(&xp, nelems, (const void*)value, type, memtype); } - + set_NC_hdirty(ncp); if(NC_doHsync(ncp)) { @@ -1512,4 +1515,3 @@ NC3_get_att( status = NC_EBADTYPE; return status; } -