From 2d3d747b17ff19e385986b1b0cd56e1beca108c8 Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Tue, 10 Feb 2015 13:51:52 -0700 Subject: [PATCH] Corrected a couple of dereferencing-null errors identified by static analysis. --- libdap2/daputil.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/libdap2/daputil.c b/libdap2/daputil.c index 5fde13e82..36885c74f 100644 --- a/libdap2/daputil.c +++ b/libdap2/daputil.c @@ -38,11 +38,22 @@ nc__testurl(const char* path, char** basenamep) char* slash = (uri->file == NULL ? NULL : strrchr(uri->file, '/')); char* dot; if(slash == NULL) slash = (char*)path; else slash++; - slash = nulldup(slash); - dot = strrchr(slash, '.'); - if(dot != NULL && dot != slash) *dot = '\0'; - if(basenamep) *basenamep=slash ; else free(slash); - ncurifree(uri); + slash = nulldup(slash); + + if(slash == NULL) + dot = NULL; + else + dot = strrchr(slash, '.'); + + if(dot != NULL && dot != slash) *dot = '\0'; + + if(basenamep) + *basenamep=slash; + else { + if(slash) + free(slash); + } + ncurifree(uri); } return ok; } @@ -289,7 +300,7 @@ dapparamcheck(NCDAPCOMMON* nccomm, const char* key, const char* subkey) } -/* This is NOT UNION */ +/* This is NOT UNION */ int nclistconcat(NClist* l1, NClist* l2) { @@ -324,7 +335,7 @@ nclistdeleteall(NClist* l, void* elem) found=1; } } - return found; + return found; } /* Collect the set of container nodes ending in "container"*/ @@ -556,7 +567,7 @@ daptopseq(CDFnode* seq) BOOL daptoplevel(CDFnode* node) { - if(node->container == NULL + if(node->container == NULL || node->container->nctype != NC_Dataset) return FALSE; return TRUE; } @@ -601,7 +612,7 @@ void dapexpandescapes(char *termstring) { char *s, *t, *endp; - + /* expand "\" escapes, e.g. "\t" to tab character; will only shorten string length, never increase it */ @@ -725,7 +736,7 @@ dap_fetch(NCDAPCOMMON* nccomm, OClink conn, const char* ce, char* baseurl = ncuribuild(nccomm->oc.url,NULL,ext,0); if(ce == NULL) LOG1(NCLOGNOTE,"fetch: %s",baseurl); - else + else LOG2(NCLOGNOTE,"fetch: %s?%s",baseurl,ce); nullfree(baseurl); #ifdef HAVE_GETTIMEOFDAY @@ -747,7 +758,7 @@ dap_fetch(NCDAPCOMMON* nccomm, OClink conn, const char* ce, fprintf(stderr,"fetch: dds:\n"); oc_dumpnode(conn,*rootp); #endif - + /* Look at the HTTP return code */ httpcode = oc_httpcode(conn); if(httpcode < 400) { @@ -810,7 +821,7 @@ repairname(const char* name, const char* badchars) if(strchr(badchars,c) != NULL) { int digit; char newchar[4]; - newchar[0] = '%'; + newchar[0] = '%'; digit = (c & 0xf0) >> 4; newchar[1] = hexdigits[digit]; digit = (c & 0x0f);