Merge pull request #170 from wtoorop/devel/clang-static-checking

Static checking
This commit is contained in:
Melinda Shore 2016-05-13 20:42:21 -08:00
commit 35f639faf1
20 changed files with 110 additions and 29 deletions

View File

@ -12,6 +12,7 @@ addons:
- libevent-dev - libevent-dev
- libev-dev - libev-dev
- valgrind - valgrind
- clang
script: script:
- mkdir tests - mkdir tests
- cd tests - cd tests

View File

@ -46,6 +46,9 @@ INSTALL = @INSTALL@
all : default @GETDNS_QUERY@ all : default @GETDNS_QUERY@
everything: default
cd src/test && $(MAKE)
default: default:
cd src && $(MAKE) $@ cd src && $(MAKE) $@

View File

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

View File

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

View File

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

View File

@ -813,7 +813,7 @@ static chain_head *add_rrset2val_chain(struct mem_funcs *mf,
; node = node->parent, n++); ; node = node->parent, n++);
for ( n -= max_labels, node = max_head->parent for ( n -= max_labels, node = max_head->parent
; n ; n && node
; n--, node = node->parent); ; n--, node = node->parent);
max_node = node; max_node = node;
@ -2624,8 +2624,8 @@ static int key_proves_nonexistance(
for ( i = rrset_iter_init(&i_spc, rrset->pkt, rrset->pkt_len) for ( i = rrset_iter_init(&i_spc, rrset->pkt, rrset->pkt_len)
; i ; i = rrset_iter_next(i)) { ; i ; i = rrset_iter_next(i)) {
if ( (ce = rrset_iter_value(i))->rr_type if ( !(ce = rrset_iter_value(i))
!= GETDNS_RRTYPE_NSEC3 || ce->rr_type != GETDNS_RRTYPE_NSEC3
/* Get the bitmap rdata field */ /* Get the bitmap rdata field */
|| !(nsec_rr = rrtype_iter_init(&nsec_spc, ce)) || !(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; offset += length;
Y = BN_bin2bn(key+offset, (int)length, NULL); Y = BN_bin2bn(key+offset, (int)length, NULL);
offset += length;
/* create the key and set its properties */ /* create the key and set its properties */
if(!Q || !P || !G || !Y || !(dsa = DSA_new())) { 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+1] = b64[ ((src[i]&0x03)<<4) | (src[i+1]>>4) ];
target[o+2] = b64[ ((src[i+1]&0x0f)<<2) ]; target[o+2] = b64[ ((src[i+1]&0x0f)<<2) ];
target[o+3] = pad64; target[o+3] = pad64;
i += 2; /* i += 2; */
o += 4; o += 4;
break; break;
case 1: 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+1] = b64[ ((src[i]&0x03)<<4) ];
target[o+2] = pad64; target[o+2] = pad64;
target[o+3] = pad64; target[o+3] = pad64;
i += 1; /* i += 1; */
o += 4; o += 4;
break; break;
case 0: 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->default_ttl:0,
(parse_state&&parse_state->origin_len)? (parse_state&&parse_state->origin_len)?
parse_state->origin:NULL, parse_state->origin:NULL,
parse_state->origin_len, parse_state?parse_state->origin_len:0,
(parse_state&&parse_state->prev_rr_len)? (parse_state&&parse_state->prev_rr_len)?
parse_state->prev_rr:NULL, parse_state->prev_rr:NULL,
parse_state->prev_rr_len); parse_state?parse_state->prev_rr_len:0);
} }
return GLDNS_WIREPARSE_ERR_OK; return GLDNS_WIREPARSE_ERR_OK;
} }

View File

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

View File

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

View File

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

View File

@ -622,7 +622,7 @@ error:
getdns_list_destroy(trust_anchor); getdns_list_destroy(trust_anchor);
getdns_list_destroy(to_validate); getdns_list_destroy(to_validate);
return GETDNS_RETURN_GOOD; return r;
} }
void callback(getdns_context *context, getdns_callback_type_t callback_type, 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) { if (testprog != NULL) {
tstmsg_prog_end(); tstmsg_prog_end();
free(testprog);
} }
testprog = strdup(prognm); testprog = strdup(prognm);
printf("TESTPROG %s START\n", testprog); printf("TESTPROG %s START\n", testprog);

View File

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

View File

@ -0,0 +1,16 @@
BaseName: 340-event-loops-scan-build
Version: 1.0
Description: Compile
CreationDate: do 28 apr 2016 16:50:43 CEST
Maintainer: Willem Toorop
Category:
Component:
CmdDepends: scan-build
Depends: 300-event-loops-configure.tpkg
Help:
Pre: 340-event-loops-scan-build.pre
Post: 340-event-loops-scan-build.post
Test: 340-event-loops-scan-build.test
AuxFiles:
Passed:
Failure:

View File

@ -0,0 +1,20 @@
# #-- 340-event-loops-scan-build.post --#
# source the master var file when it's there
if [ -f ../.tpkg.var.master ]
then
source ../.tpkg.var.master
else
(
cd ..
[ -f "${TPKG_SRCDIR}/setup-env.sh" ] \
&& sh "${TPKG_SRCDIR}/setup-env.sh"
) && source ../.tpkg.var.master
fi
# use .tpkg.var.test for in test variable passing
[ -f .tpkg.var.test ] && source .tpkg.var.test
for f in `cat restore-srcdir-configure-settings`
do
mv "${SRCROOT}/${f}.build-event-loops" "${SRCROOT}/${f}"
done

View File

@ -0,0 +1,24 @@
# #-- 340-event-loops-scan-build.pre--#
# source the master var file when it's there
if [ -f ../.tpkg.var.master ]
then
source ../.tpkg.var.master
else
(
cd ..
[ -f "${TPKG_SRCDIR}/setup-env.sh" ] \
&& sh "${TPKG_SRCDIR}/setup-env.sh"
) && source ../.tpkg.var.master
fi
# use .tpkg.var.test for in test variable passing
[ -f .tpkg.var.test ] && source .tpkg.var.test
echo "" > restore-srcdir-configure-settings
for f in `grep 'CONFIG_[FH][IE][LA][ED][SE]' "${SRCROOT}/configure.ac" | sed -e 's/^.*(\[//g' -e 's/\])//g'`
do
if [ -f "${SRCROOT}/$f" ]
then
mv "${SRCROOT}/${f}" "${SRCROOT}/${f}.build-event-loops" && \
echo "$f" >> restore-srcdir-configure-settings
fi
done

View File

@ -0,0 +1,9 @@
# #-- 340-event-loops-scan-build.test --#
# source the master var file when it's there
[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
# 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 --status-bugs make everything

View File

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