From 2e63708ec817220844a34e446da1297c74513f9e Mon Sep 17 00:00:00 2001 From: Utz-Uwe Haus <uhaus@hpe.com> Date: Thu, 11 Aug 2022 07:36:59 +0000 Subject: [PATCH] Fix compiler warnings mostly sscanf arguments and uninitialized variables on error path cleanups --- maestro/attributes.c | 18 +++++++++--------- maestro/core.c | 2 +- maestro/ofi.c | 11 +++++++---- tests/simple_dist_client.c | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/maestro/attributes.c b/maestro/attributes.c index 460ba230..353faaf2 100644 --- a/maestro/attributes.c +++ b/maestro/attributes.c @@ -314,7 +314,7 @@ mstro_parse_number_array(char *str, size_t *num) { /*get first number */ token = strtok_r(str,sep, &tmp); while(token != NULL) { - sscanf(token, "%zd", &num[i]); + sscanf(token, "%zu", &num[i]); token = strtok_r(NULL,sep, &tmp); i++; } @@ -340,37 +340,37 @@ mstro_parse_mmbLayout_irregular_1D(char *str, mmbLayout **dist_layout) { /** Reading layout type ... should be MMB_IRREGULAR **/ if(strcmp(token, "MMB_IRREGULAR") != 0 ) { - ERR("Cannot parse other mmb_layout types. Only support MMB_IRREGULAR \n "); + ERR("Cannot parse other mmb_layout types. Only support MMB_IRREGULAR\n"); return MSTRO_INVARG; } /*reading n_dims ... should be always 1 */ token = strtok_r(NULL, sep, &tmp); DEBUG("parsing token %s \n", token); - sscanf(token, "%zd", &temp_int); + sscanf(token, "%zu", &temp_int); if (temp_int != 1 ) { - ERR("Can not parse %zd layouts, only support 1D mmbLayout \n ", temp_int); + ERR("Can not parse %zu layouts, only support 1D mmbLayout\n", temp_int); return MSTRO_INVARG; } /*reading index ...*/ token = strtok_r(NULL, sep, &tmp); DEBUG("parsing token %s \n", token); - sscanf(token, "%zd", &index); + sscanf(token, "%zu", &index); /*reading element_size_bytes ...*/ token = strtok_r(NULL, sep, &tmp); DEBUG("parsing token %s \n", token); - sscanf(token, "%zd", &element_size_bytes); + sscanf(token, "%zu", &element_size_bytes); if(element_size_bytes == 0) { - ERR("mmbLayout element_size_bytes should be greater than 1 \n "); + ERR("mmbLayout element_size_bytes should be greater than 1\n"); return MSTRO_INVARG; } /*reading n_blocks ...*/ token = strtok_r(NULL, sep, &tmp); - DEBUG("parsing token %s \n", token); - sscanf(token, "%zd", &n_blocks); + DEBUG("parsing token %s\n", token); + sscanf(token, "%zu", &n_blocks); offsets = malloc(n_blocks*sizeof(size_t)); lengths = malloc(n_blocks*sizeof(size_t)); diff --git a/maestro/core.c b/maestro/core.c index 77015f4c..c22908f9 100644 --- a/maestro/core.c +++ b/maestro/core.c @@ -647,7 +647,7 @@ mstro_core_finalize(void) mstro_status s_sub=MSTRO_OK, s_transp=MSTRO_OK, s_pm=MSTRO_OK, s_pool=MSTRO_OK, s_hb=MSTRO_OK, - s_schema=MSTRO_OK, s_mamba=MSTRO_OK, s_erl=MSTRO_OK, s_memlock; + s_schema=MSTRO_OK, s_mamba=MSTRO_OK, s_erl=MSTRO_OK, s_memlock=MSTRO_OK; mmbError x = MMB_OK; if(g_initdata==NULL) { diff --git a/maestro/ofi.c b/maestro/ofi.c index da7320cf..f72d0ec2 100644 --- a/maestro/ofi.c +++ b/maestro/ofi.c @@ -2750,6 +2750,7 @@ mstro_ofi__select_endpoint__submit_read( { mstro_event event=NULL; mstro_ofi_msg_context ctx=NULL; + struct mstro_endpoint *myep = NULL; mstro_status stat=mstro_event_create( g_ofi_rdma_edom, @@ -2779,7 +2780,7 @@ mstro_ofi__select_endpoint__submit_read( * we progress the request handle and indicate an error state in * it. */ - struct mstro_endpoint *myep = closure->my_eps->eps + closure->my_eps_idx; + myep = closure->my_eps->eps + closure->my_eps_idx; const Mstro__Endpoint *remote = closure->remote->eps->eps[closure->remote_idx]; const Mstro__OfiMemoryRegion *inforeg = closure->remote->eps->inforegs[closure->remote_idx]; @@ -2811,7 +2812,8 @@ BAILOUT: mstro_event_destroy(event); } if(ctx) { - mstro_ofi__forget_ctx(myep, ctx); + if(myep) + mstro_ofi__forget_ctx(myep, ctx); mstro_ofi__msg_context_destroy(ctx); } if(closure) { @@ -3181,8 +3183,9 @@ mstro_ofi__check_and_handle_cq(struct mstro_endpoint *ep, max_miss = (max_miss>num_miss)?max_miss:num_miss; min_miss = (min_miss<num_miss)?min_miss:num_miss; avg_miss += num_miss; - max_hits = (max_hits>ret)?max_hits:ret; - min_hits = (min_hits<ret)?min_hits:ret; + assert(ret>=0); + max_hits = (max_hits>(size_t)ret) ? max_hits : (size_t)ret; + min_hits = (min_hits<(size_t)ret) ? min_hits : (size_t)ret; avg_hits += ret; if(trials >= 1000) { diff --git a/tests/simple_dist_client.c b/tests/simple_dist_client.c index 15b1623d..5c3eeae9 100644 --- a/tests/simple_dist_client.c +++ b/tests/simple_dist_client.c @@ -121,7 +121,7 @@ CHEAT_TEST(simple_dist_cdo, int64_t sync_size = 1; double *data; - double *dist_buf, *dist_buf2, *dist_buf3; + double *dist_buf=NULL, *dist_buf2=NULL, *dist_buf3=NULL; int64_t dist_size = 50 * sizeof(double); int64_t dist_size2 = 75 * sizeof(double); int64_t dist_size3 = 75 * sizeof(double); -- GitLab