warning fixes (#551)

* fix Wstrict-prototypes warnings found by clang

also fix usage_long() call

Signed-off-by: Gabriel Ganne <gabriel.ganne@enea.com>

* fix Wunreachable-code-break warnings found by clang

Signed-off-by: Gabriel Ganne <gabriel.ganne@enea.com>

* fix Wshadow warnings found by clang

Signed-off-by: Gabriel Ganne <gabriel.ganne@enea.com>

* fix Wmissing-noreturn warning found by clang

Signed-off-by: Gabriel Ganne <gabriel.ganne@enea.com>

* ix memory leak found by clang

Signed-off-by: Gabriel Ganne <gabriel.ganne@enea.com>

* fix Wmisleading-indentation warnings raised by gcc-6

Signed-off-by: Gabriel Ganne <gabriel.ganne@enea.com>

* fix warning: Value stored to 'ptr' during its initialization is never read found by clang

Signed-off-by: Gabriel Ganne <gabriel.ganne@enea.com>

* fix warning: The left operand of '>' is a garbage value found by clang

Signed-off-by: Gabriel Ganne <gabriel.ganne@enea.com>

* fix memory leak in global cleanup

Signed-off-by: Gabriel Ganne <gabriel.ganne@enea.com>
This commit is contained in:
Gabriel Ganne 2017-04-20 22:33:15 +02:00 committed by Bruce A. Mah
parent 5e52a8460b
commit 5ab2132ce3
6 changed files with 27 additions and 21 deletions

View File

@ -48,9 +48,10 @@ const char *cJSON_GetErrorPtr(void) {return global_ep;}
static int cJSON_strcasecmp(const char *s1,const char *s2)
{
if (!s1) return (s1==s2)?0:1;if (!s2) return 1;
for(; tolower(*s1) == tolower(*s2); ++s1, ++s2) if(*s1 == 0) return 0;
return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2);
if (!s1) return (s1==s2)?0:1;
if (!s2) return 1;
for(; tolower(*s1) == tolower(*s2); ++s1, ++s2) if(*s1 == 0) return 0;
return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2);
}
static void *(*cJSON_malloc)(size_t sz) = malloc;
@ -202,7 +203,7 @@ static unsigned parse_hex4(const char *str)
static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
static const char *parse_string(cJSON *item,const char *str,const char **ep)
{
const char *ptr=str+1,*end_ptr=str+1;char *ptr2;char *out;int len=0;unsigned uc,uc2;
const char *ptr,*end_ptr=str+1;char *ptr2;char *out;int len=0;unsigned uc,uc2;
if (*str!='\"') {*ep=str;return 0;} /* not a string! */
while (*end_ptr!='\"' && *end_ptr && ++len)
@ -620,7 +621,8 @@ static char *print_object(cJSON *item,int depth,int fmt,printbuffer *p)
len=(fmt?1:0)+(child->next?1:0);
ptr=ensure(p,len+1); if (!ptr) return 0;
if (child->next) *ptr++=',';
if (fmt) *ptr++='\n';*ptr=0;
if (fmt) *ptr++='\n';
*ptr=0;
p->offset+=len;
child=child->next;
}
@ -670,7 +672,8 @@ static char *print_object(cJSON *item,int depth,int fmt,printbuffer *p)
*ptr++=':';if (fmt) *ptr++='\t';
strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
if (i!=numentries-1) *ptr++=',';
if (fmt) *ptr++='\n';*ptr=0;
if (fmt) *ptr++='\n';
*ptr=0;
cJSON_free(names[i]);cJSON_free(entries[i]);
}
@ -700,7 +703,7 @@ void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddIte
void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));}
cJSON *cJSON_DetachItemFromArray(cJSON *array,int which) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return 0;
if (c->prev) c->prev->next=c->next;if (c->next) c->next->prev=c->prev;if (c==array->child) array->child=c->next;c->prev=c->next=0;return c;}
if (c->prev) {c->prev->next=c->next;}if (c->next) {c->next->prev=c->prev;}if (c==array->child) {array->child=c->next;} c->prev=c->next=0;return c;}
void cJSON_DeleteItemFromArray(cJSON *array,int which) {cJSON_Delete(cJSON_DetachItemFromArray(array,which));}
cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {int i=0;cJSON *c=object->child;while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;if (c) return cJSON_DetachItemFromArray(object,i);return 0;}
void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {cJSON_Delete(cJSON_DetachItemFromObject(object,string));}

View File

@ -354,9 +354,9 @@ iperf_set_test_burst(struct iperf_test *ipt, int burst)
}
void
iperf_set_test_server_port(struct iperf_test *ipt, int server_port)
iperf_set_test_server_port(struct iperf_test *ipt, int srv_port)
{
ipt->server_port = server_port;
ipt->server_port = srv_port;
}
void
@ -445,9 +445,9 @@ iperf_set_test_unit_format(struct iperf_test *ipt, char unit_format)
}
void
iperf_set_test_bind_address(struct iperf_test *ipt, char *bind_address)
iperf_set_test_bind_address(struct iperf_test *ipt, char *bnd_address)
{
ipt->bind_address = strdup(bind_address);
ipt->bind_address = strdup(bnd_address);
}
void
@ -759,11 +759,11 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
#if defined(HAVE_SCTP)
set_protocol(test, Psctp);
client_flag = 1;
break;
#else /* HAVE_SCTP */
i_errno = IEUNIMP;
return -1;
#endif /* HAVE_SCTP */
break;
case OPT_NUMSTREAMS:
#if defined(linux) || defined(__FreeBSD__)
@ -1622,6 +1622,7 @@ send_results(struct iperf_test *test)
}
cJSON_AddStringToObject(j, "server_output_text", output);
free(output);
}
}
@ -2489,7 +2490,7 @@ iperf_print_results(struct iperf_test *test)
struct iperf_stream *sp = NULL;
iperf_size_t bytes_sent, total_sent = 0;
iperf_size_t bytes_received, total_received = 0;
double start_time, end_time, avg_jitter = 0.0, lost_percent;
double start_time, end_time = 0.0, avg_jitter = 0.0, lost_percent;
double bandwidth;
/* print final summary for all intervals */

View File

@ -169,7 +169,7 @@ void iperf_reporter_callback(struct iperf_test * test);
* returns NULL on failure
*
*/
struct iperf_test *iperf_new_test();
struct iperf_test *iperf_new_test(void);
int iperf_defaults(struct iperf_test * testp);
@ -222,8 +222,8 @@ int iperf_send(struct iperf_test *, fd_set *) /* __attribute__((hot)) */;
int iperf_recv(struct iperf_test *, fd_set *);
void iperf_catch_sigend(void (*handler)(int));
void iperf_got_sigend(struct iperf_test *test) __attribute__ ((noreturn));
void usage();
void usage_long();
void usage(void);
void usage_long(FILE * f);
void warning(char *);
int iperf_exchange_results(struct iperf_test *);
int iperf_init_test(struct iperf_test *);

View File

@ -82,7 +82,7 @@ iperf_errexit(struct iperf_test *test, const char *format, ...)
int i_errno;
char *
iperf_strerror(int i_errno)
iperf_strerror(int int_errno)
{
static char errstr[256];
int len, perr, herr;
@ -91,7 +91,7 @@ iperf_strerror(int i_errno)
len = sizeof(errstr);
memset(errstr, 0, len);
switch (i_errno) {
switch (int_errno) {
case IENONE:
snprintf(errstr, len, "no error");
break;

View File

@ -434,6 +434,9 @@ cleanup_server(struct iperf_test *test)
tmr_cancel(test->omit_timer);
test->omit_timer = NULL;
}
if (test->congestion_used != NULL) {
free(test->congestion_used);
}
}

View File

@ -100,7 +100,7 @@ main(int argc, char **argv)
if (iperf_parse_arguments(test, argc, argv) < 0) {
iperf_err(test, "parameter error - %s", iperf_strerror(i_errno));
fprintf(stderr, "\n");
usage_long();
usage_long(stdout);
exit(1);
}
@ -115,7 +115,7 @@ main(int argc, char **argv)
static jmp_buf sigend_jmp_buf;
static void
static void __attribute__ ((noreturn))
sigend_handler(int sig)
{
longjmp(sigend_jmp_buf, 1);
@ -153,7 +153,6 @@ run(struct iperf_test *test)
iperf_err(test, "error - %s", iperf_strerror(i_errno));
if (rc < -1) {
iperf_errexit(test, "exiting");
break;
}
}
iperf_reset_test(test);