Static checking fixes

This commit is contained in:
Willem Toorop 2016-04-29 12:00:17 +02:00
parent 9ac9e0e6d0
commit a8dbb3dd51
15 changed files with 40 additions and 39 deletions

View File

@ -2473,7 +2473,8 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
return GETDNS_RETURN_GOOD;
invalid_parameter:
r = GETDNS_RETURN_INVALID_PARAMETER;
_getdns_upstreams_dereference(upstreams);
return GETDNS_RETURN_INVALID_PARAMETER;
error:
_getdns_upstreams_dereference(upstreams);
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
@ -3637,7 +3638,7 @@ getdns_context_get_suffix(getdns_context *context, getdns_list **value)
else
*value = list;
return GETDNS_RETURN_GOOD;
return r;
}
getdns_return_t

View File

@ -240,7 +240,7 @@ getdns_rr_dict2wire(
if (r != GETDNS_RETURN_GOOD && r != GETDNS_RETURN_NEED_MORE_SPACE)
return r;
if (!(buf = malloc(buf_len)))
if (!(buf = malloc(buf_len ? buf_len : 1)))
return GETDNS_RETURN_MEMORY_ERROR;
if (!r)
@ -658,11 +658,16 @@ _getdns_wire2msg_dict_scan(struct mem_funcs *mf,
result, "question", rr_dict)))
goto error;
break;
default:
case GLDNS_SECTION_ANSWER:
case GLDNS_SECTION_AUTHORITY:
case GLDNS_SECTION_ADDITIONAL:
if ((r = _getdns_list_append_this_dict(
sections[section], rr_dict)))
goto error;
break;
default:
r = GETDNS_RETURN_GENERIC_ERROR;
goto error;
}
rr_dict = NULL;
}
@ -849,7 +854,7 @@ getdns_msg_dict2wire(
if (r != GETDNS_RETURN_GOOD && r != GETDNS_RETURN_NEED_MORE_SPACE)
return r;
if (!(buf = malloc(buf_len)))
if (!(buf = malloc(buf_len ? buf_len : 1)))
return GETDNS_RETURN_MEMORY_ERROR;
if (!r)

View File

@ -65,7 +65,7 @@ static char *_json_ptr_first(const struct mem_funcs *mf,
if (!(next_ref = strchr(jptr, '/')))
next_ref = strchr(jptr, '\0');
if (next_ref - jptr > first_sz)
if (next_ref - jptr + 1 > first_sz || !first)
first = GETDNS_XMALLOC(*mf, char, next_ref - jptr + 1);
for (j = first, k = jptr; k < next_ref; j++, k++)
@ -484,7 +484,6 @@ _getdns_dict_copy(const struct getdns_dict * srcdict,
if (!*dstdict)
return GETDNS_RETURN_GENERIC_ERROR;
retval = GETDNS_RETURN_GOOD;
RBTREE_FOR(item, struct getdns_dict_item *,
(struct _getdns_rbtree_t *)&(srcdict->root)) {
key = (char *) item->node.key;
@ -508,6 +507,9 @@ _getdns_dict_copy(const struct getdns_dict * srcdict,
retval = getdns_dict_set_list(*dstdict, key,
item->i.data.list);
break;
default:
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
break;
}
if (retval != GETDNS_RETURN_GOOD) {
getdns_dict_destroy(*dstdict);;

View File

@ -828,7 +828,7 @@ static chain_head *add_rrset2val_chain(struct mem_funcs *mf,
; node = node->parent, n++);
for ( n -= max_labels, node = max_head->parent
; n
; n && node
; n--, node = node->parent);
max_node = node;
@ -2646,8 +2646,8 @@ static int key_proves_nonexistance(
for ( i = rrset_iter_init(&i_spc, rrset->pkt, rrset->pkt_len)
; i ; i = rrset_iter_next(i)) {
if ( (ce = rrset_iter_value(i))->rr_type
!= GETDNS_RRTYPE_NSEC3
if ( !(ce = rrset_iter_value(i))
|| ce->rr_type != GETDNS_RRTYPE_NSEC3
/* Get the bitmap rdata field */
|| !(nsec_rr = rrtype_iter_init(&nsec_spc, ce))

View File

@ -206,7 +206,6 @@ gldns_key_buf2dsa_raw(unsigned char* key, size_t len)
offset += length;
Y = BN_bin2bn(key+offset, (int)length, NULL);
offset += length;
/* create the key and set its properties */
if(!Q || !P || !G || !Y || !(dsa = DSA_new())) {

View File

@ -637,7 +637,7 @@ int gldns_b64_ntop(uint8_t const *src, size_t srclength,
target[o+1] = b64[ ((src[i]&0x03)<<4) | (src[i+1]>>4) ];
target[o+2] = b64[ ((src[i+1]&0x0f)<<2) ];
target[o+3] = pad64;
i += 2;
/* i += 2; */
o += 4;
break;
case 1:
@ -646,7 +646,7 @@ int gldns_b64_ntop(uint8_t const *src, size_t srclength,
target[o+1] = b64[ ((src[i]&0x03)<<4) ];
target[o+2] = pad64;
target[o+3] = pad64;
i += 1;
/* i += 1; */
o += 4;
break;
case 0:

View File

@ -892,10 +892,10 @@ int gldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len,
parse_state?parse_state->default_ttl:0,
(parse_state&&parse_state->origin_len)?
parse_state->origin:NULL,
parse_state->origin_len,
parse_state?parse_state->origin_len:0,
(parse_state&&parse_state->prev_rr_len)?
parse_state->prev_rr:NULL,
parse_state->prev_rr_len);
parse_state?parse_state->prev_rr_len:0);
}
return GLDNS_WIREPARSE_ERR_OK;
}

View File

@ -691,7 +691,7 @@ _getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop,
getdns_dict *add_opt_parameters;
int have_add_opt_parameters;
getdns_list *options;
getdns_list *options = NULL;
size_t noptions = 0;
size_t i;

View File

@ -206,12 +206,13 @@ void* run_server(void* data) {
}
getdns_dict_destroy(dns_msg);
r = getdns_general_sync(ctxt, qname_str, qtype, NULL, &responses[num_received].reply);
free(qname_str);
if (r) {
fprintf( stderr, "Could query for \"%s\" %d: \"%s\"\n", qname_str, (int)qtype
, getdns_get_errorstr_by_id(r));
free(qname_str);
continue;
}
free(qname_str);
if ((r = getdns_dict_set_int(responses[num_received].reply, "/replies_tree/0/header/id", qid))) {
fprintf( stderr, "Could not set message ID on reply dict: \"%s\"\n"
, getdns_get_errorstr_by_id(r));

View File

@ -29,6 +29,7 @@
#include "check_getdns_transport.h"
#include "check_getdns_common.h"
#include <pthread.h>
#include <assert.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
@ -111,7 +112,9 @@ void* run_transport_server(void* data) {
conn = accept(tcp, (struct sockaddr *) &client_addr, &len);
/* throw away the length */
n = read(conn, tcplength, 2);
assert(n == 2);
n = read(conn, mesg, 65536);
assert(n == ((tcplength[0] << 8) | tcplength[1]));
tcp_count++;
} else {
fprintf(stderr, "Timeout in run_transport_server\n");
@ -145,12 +148,13 @@ void* run_transport_server(void* data) {
}
getdns_dict_destroy(dns_msg);
r = getdns_general_sync(ctxt, qname_str, qtype, NULL, &dns_msg);
free(qname_str);
if (r) {
fprintf( stderr, "Could query for \"%s\" %d: \"%s\"\n", qname_str, (int)qtype
, getdns_get_errorstr_by_id(r));
free(qname_str);
continue;
}
free(qname_str);
if ((r = getdns_dict_set_int(dns_msg, "/replies_tree/0/header/id", qid))) {
fprintf( stderr, "Could not set message ID on reply dict: \"%s\"\n"
, getdns_get_errorstr_by_id(r));

View File

@ -621,7 +621,7 @@ error:
getdns_list_destroy(trust_anchor);
getdns_list_destroy(to_validate);
return GETDNS_RETURN_GOOD;
return r;
}
void callback(getdns_context *context, getdns_callback_type_t callback_type,

View File

@ -45,7 +45,6 @@ tstmsg_prog_begin(char *prognm)
{
if (testprog != NULL) {
tstmsg_prog_end();
free(testprog);
}
testprog = strdup(prognm);
printf("TESTPROG %s START\n", testprog);

View File

@ -56,7 +56,7 @@ tst_bindatasetget(void)
size_t index = 0;
getdns_return_t retval;
struct getdns_list *list = NULL;
struct getdns_bindata *new_bindata = NULL;
struct getdns_bindata new_bindata = { 0, NULL };
struct getdns_bindata *ans_bindata = NULL;
tstmsg_case_begin("tst_bindatasetget");
@ -101,12 +101,10 @@ tst_bindatasetget(void)
/* test set and get legitimate use case */
new_bindata =
(struct getdns_bindata *) malloc(sizeof(struct getdns_bindata));
new_bindata->size = strlen("foobar") + 1;
new_bindata->data = (uint8_t *) "foobar";
new_bindata.size = strlen("foobar") + 1;
new_bindata.data = (uint8_t *) "foobar";
getdns_list_set_bindata(list, index, new_bindata);
getdns_list_set_bindata(list, index, &new_bindata);
retval = getdns_list_get_bindata(list, index, &ans_bindata);
snprintf(msg, sizeof(msg),
"getdns_list_set/get_bindata,retval = %d, bindata->data = %d,%s",
@ -378,7 +376,7 @@ tst_create(void)
tstmsg_case_msg("getdns_list_get_length(list)");
retval = getdns_list_get_length(list, &index);
snprintf(msg, sizeof(msg), "list length = %d", (int) index);
snprintf(msg, sizeof(msg), "list length = %d, retval = %d", (int) index, retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_length()");

View File

@ -4,13 +4,6 @@
# use .tpkg.var.test for in test variable passing
[ -f .tpkg.var.test ] && source .tpkg.var.test
(
cd "${BUILDDIR}/build-event-loops"
make clean
scan-build -o ../scan-build-reports -v make everything
) && if grep "No bugs found" result.340-event-loops-scan-build
then
exit 0
else
exit 1
fi
cd "${BUILDDIR}/build-event-loops"
make clean
scan-build -o ../scan-build-reports -v --status-bugs make everything

View File

@ -493,8 +493,7 @@ _getdns_create_reply_dict(getdns_context *context, getdns_network_req *req,
gldns_pkt_section section;
uint8_t canonical_name_space[256], owner_name_space[256],
query_name_space[256];
const uint8_t *canonical_name = canonical_name_space, *owner_name,
*query_name;
const uint8_t *canonical_name, *owner_name, *query_name;
size_t canonical_name_len = sizeof(canonical_name_space),
owner_name_len = sizeof(owner_name_space),
query_name_len = sizeof(query_name_space);