From: Jordan Lee Date: Wed, 10 Jul 2013 22:28:40 +0000 (+0000) Subject: fix a couple of unlikely-to-be-triggered errors reported by clang static analyzer X-Git-Tag: 2.81~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=af3481400f13fa196a5cf55e56fb287d10e6c4b6;p=transmission fix a couple of unlikely-to-be-triggered errors reported by clang static analyzer --- diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index 9573f1039..934ea5b23 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -1593,6 +1593,7 @@ addTorrentImpl (struct tr_rpc_idle_data * data, tr_ctor * ctor) } else if (err == TR_PARSE_ERR) { + key = 0; result = "invalid or corrupt torrent file"; } else if (err == TR_PARSE_DUPLICATE) @@ -1602,7 +1603,7 @@ addTorrentImpl (struct tr_rpc_idle_data * data, tr_ctor * ctor) result = "duplicate torrent"; } - if (tor != NULL) + if (tor && key) { tr_variant fields; tr_variantInitList (&fields, 3); @@ -1612,6 +1613,7 @@ addTorrentImpl (struct tr_rpc_idle_data * data, tr_ctor * ctor) addInfo (tor, tr_variantDictAdd (data->args_out, key), &fields); notify (data->session, TR_RPC_TORRENT_ADDED, tor); tr_variantFree (&fields); + result = NULL; } tr_idle_function_done (data, result); diff --git a/libtransmission/utils.c b/libtransmission/utils.c index e5ce58ae1..80ca68136 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -306,7 +306,15 @@ tr_mkdirp (const char * path_in, int tmperr; int rv; struct stat sb; - char * path = tr_strdup (path_in); + char * path; + + /* make a temporary copy of path */ + path = tr_strdup (path_in); + if (path == NULL) + { + errno = ENOMEM; + return -1; + } /* walk past the root */ p = path; @@ -379,6 +387,8 @@ tr_buildPath (const char *first_element, ...) } pch = buf = tr_new (char, bufLen); va_end (vl); + if (buf == NULL) + return NULL; /* pass 2: build the string piece by piece */ va_start (vl, first_element); @@ -475,8 +485,12 @@ tr_strndup (const void * in, int len) else if (in) { out = tr_malloc (len + 1); - memcpy (out, in, len); - out[len] = '\0'; + + if (out != NULL) + { + memcpy (out, in, len); + out[len] = '\0'; + } } return out; @@ -1344,23 +1358,38 @@ tr_parseNumberRange (const char * str_in, int len, int * setmeCount) n += r->high + 1 - r->low; } sorted = tr_new (int, n); - for (l=ranges; l!=NULL; l=l->next) + if (sorted == NULL) { - int i; - const struct number_range * r = l->data; - for (i=r->low; i<=r->high; ++i) - sorted[n2++] = i; + n = 0; + uniq = NULL; } - qsort (sorted, n, sizeof (int), compareInt); - assert (n == n2); + else + { + for (l=ranges; l!=NULL; l=l->next) + { + int i; + const struct number_range * r = l->data; + for (i=r->low; i<=r->high; ++i) + sorted[n2++] = i; + } + qsort (sorted, n, sizeof (int), compareInt); + assert (n == n2); - /* remove duplicates */ - uniq = tr_new (int, n); - for (i=n=0; i