From 01f60b879ee2359a7d8ffa5070621e51f1fefb51 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Sat, 25 Oct 2025 11:35:38 -0400 Subject: [PATCH 1/8] Replace sprintf with snprintf Mac OS clang warns that sprintf is deprecated. Replace it with snprintf. Signed-off-by: Joseph Schuchart --- ompi/communicator/comm_cid.c | 6 ++-- ompi/instance/instance.c | 4 +-- .../ftagree/coll_ftagree_earlyreturning.c | 4 +-- ompi/mca/coll/ucc/coll_ucc_module.c | 6 ++-- .../monitoring/common_monitoring_coll.c | 5 +-- .../hook/comm_method/hook_comm_method_fns.c | 36 ++++++++++--------- .../sharedfp/lockedfile/sharedfp_lockedfile.c | 2 +- opal/mca/btl/smcuda/btl_smcuda.c | 2 +- opal/mca/btl/smcuda/btl_smcuda_component.c | 5 +-- opal/mca/btl/tcp/btl_tcp_component.c | 8 ++--- opal/util/timings.h | 31 ++++++++-------- test/datatype/position.c | 4 +-- test/simple/crisscross.c | 2 +- test/simple/no-disconnect.c | 2 +- test/simple/parallel_r64.c | 2 +- test/simple/parallel_r8.c | 2 +- test/simple/parallel_w64.c | 2 +- test/simple/parallel_w8.c | 2 +- test/support/support.h | 18 +++++----- 19 files changed, 74 insertions(+), 69 deletions(-) diff --git a/ompi/communicator/comm_cid.c b/ompi/communicator/comm_cid.c index 8546b700401..22967d3dfb4 100644 --- a/ompi/communicator/comm_cid.c +++ b/ompi/communicator/comm_cid.c @@ -417,7 +417,7 @@ static int ompi_comm_ext_cid_new_block (ompi_communicator_t *newcomm, ompi_commu char msg_string[1024]; switch (rc) { case PMIX_ERR_UNREACH: - sprintf(msg_string,"PMIx server unreachable"); + snprintf(msg_string, sizeof(msg_string), "PMIx server unreachable"); opal_show_help("help-comm.txt", "MPI function not supported", true, @@ -427,7 +427,7 @@ static int ompi_comm_ext_cid_new_block (ompi_communicator_t *newcomm, ompi_commu rc = MPI_ERR_UNSUPPORTED_OPERATION; break; case PMIX_ERR_NOT_SUPPORTED: - sprintf(msg_string,"PMIx server does not support PMIx Group operations"); + snprintf(msg_string, sizeof(msg_string), "PMIx server does not support PMIx Group operations"); opal_show_help("help-comm.txt", "MPI function not supported", true, @@ -577,7 +577,7 @@ int ompi_comm_nextcid_nb (ompi_communicator_t *newcomm, ompi_communicator_t *com functions but the pml does not support these functions so return not supported */ if (NULL == comm) { char msg_string[1024]; - sprintf(msg_string,"The PML being used - %s - does not support MPI sessions related features", + snprintf(msg_string, sizeof(msg_string), "The PML being used - %s - does not support MPI sessions related features", mca_pml_base_selected_component.pmlm_version.mca_component_name); opal_show_help("help-comm.txt", "MPI function not supported", diff --git a/ompi/instance/instance.c b/ompi/instance/instance.c index 2596c1decf5..103358cb527 100644 --- a/ompi/instance/instance.c +++ b/ompi/instance/instance.c @@ -1292,7 +1292,7 @@ static int ompi_instance_group_pmix_pset (ompi_instance_t *instance, const char ret = MPI_ERR_ARG; /* pset_name not valid */ break; case PMIX_ERR_UNREACH: - sprintf(msg_string,"PMIx server unreachable"); + snprintf(msg_string, sizeof(msg_string), "PMIx server unreachable"); opal_show_help("help-comm.txt", "MPI function not supported", true, @@ -1301,7 +1301,7 @@ static int ompi_instance_group_pmix_pset (ompi_instance_t *instance, const char ret = MPI_ERR_UNSUPPORTED_OPERATION; break; case PMIX_ERR_NOT_SUPPORTED: - sprintf(msg_string,"PMIx server does not support PMIX_QUERY_PSET_MEMBERSHIP operation"); + snprintf(msg_string, sizeof(msg_string), "PMIx server does not support PMIX_QUERY_PSET_MEMBERSHIP operation"); opal_show_help("help-comm.txt", "MPI function not supported", true, diff --git a/ompi/mca/coll/ftagree/coll_ftagree_earlyreturning.c b/ompi/mca/coll/ftagree/coll_ftagree_earlyreturning.c index 73ef2f06374..50c58589126 100644 --- a/ompi/mca/coll/ftagree/coll_ftagree_earlyreturning.c +++ b/ompi/mca/coll/ftagree/coll_ftagree_earlyreturning.c @@ -497,7 +497,7 @@ static void era_debug_print_group(int lvl, ompi_group_t *group, ompi_communicato } s = 128 + n * 16; str = (char*)malloc(s); - sprintf(str, "Group of size %d. Ranks in %d.%d: (", n, comm->c_index, comm->c_epoch); + snprintf(str, s, "Group of size %d. Ranks in %d.%d: (", n, comm->c_index, comm->c_epoch); p = strlen(str); for(i = 0; i < n; i++) { snprintf(str + p, s - p, "%d%s", gra[i], i==n-1 ? "" : ", "); @@ -2283,7 +2283,7 @@ static void send_msg(ompi_communicator_t *comm, b++; } while(w < 256); if( strlen(strbytes) >= 252 ) { - sprintf(strbytes + 252, "..."); + snprintf(strbytes + 252, 256 - 252, "..."); } OPAL_OUTPUT_VERBOSE((30, ompi_ftmpi_output_handle, diff --git a/ompi/mca/coll/ucc/coll_ucc_module.c b/ompi/mca/coll/ucc/coll_ucc_module.c index 00b3f31ad73..dfa3c1cf96c 100644 --- a/ompi/mca/coll/ucc/coll_ucc_module.c +++ b/ompi/mca/coll/ucc/coll_ucc_module.c @@ -312,14 +312,14 @@ static int mca_coll_ucc_init_ctx(ompi_communicator_t* comm) goto cleanup_lib; } - sprintf(str_buf, "%u", ompi_proc_world_size()); + snprintf(str_buf, sizeof(str_buf), "%u", ompi_proc_world_size()); if (UCC_OK != ucc_context_config_modify(ctx_config, NULL, "ESTIMATED_NUM_EPS", str_buf)) { UCC_ERROR("UCC context config modify failed for estimated_num_eps"); goto cleanup_lib; } - sprintf(str_buf, "%u", opal_process_info.num_local_peers + 1); + snprintf(str_buf, sizeof(str_buf), "%u", opal_process_info.num_local_peers + 1); if (UCC_OK != ucc_context_config_modify(ctx_config, NULL, "ESTIMATED_NUM_PPN", str_buf)) { UCC_ERROR("UCC context config modify failed for estimated_num_eps"); @@ -327,7 +327,7 @@ static int mca_coll_ucc_init_ctx(ompi_communicator_t* comm) } if (ucc_api_major > 1 || (ucc_api_major == 1 && ucc_api_minor >= 6)) { - sprintf(str_buf, "%u", opal_process_info.my_local_rank); + snprintf(str_buf, sizeof(str_buf), "%u", opal_process_info.my_local_rank); if (UCC_OK != ucc_context_config_modify(ctx_config, NULL, "NODE_LOCAL_ID", str_buf)) { UCC_ERROR("UCC context config modify failed for node_local_id"); diff --git a/ompi/mca/common/monitoring/common_monitoring_coll.c b/ompi/mca/common/monitoring/common_monitoring_coll.c index a7fa7bdb0df..b1255502f49 100644 --- a/ompi/mca/common/monitoring/common_monitoring_coll.c +++ b/ompi/mca/common/monitoring/common_monitoring_coll.c @@ -70,7 +70,8 @@ static inline void mca_common_monitoring_coll_cache(mca_monitoring_coll_data_t*d assert( 0 < size ); /* Allocate enough space for list (add 1 to keep the final '\0' if already exact size) */ max_length = snprintf(NULL, 0, "%d,", world_size - 1) + 1; - tmp_procs = malloc((1 + max_length * size) * sizeof(char)); + int bufsize = (1 + max_length * size) * sizeof(char); + tmp_procs = malloc(bufsize); if( NULL == tmp_procs ) { OPAL_MONITORING_PRINT_ERR("Cannot allocate memory for caching proc list."); } else { @@ -78,7 +79,7 @@ static inline void mca_common_monitoring_coll_cache(mca_monitoring_coll_data_t*d /* Build procs list */ for(i = 0; i < size; ++i) { if( OPAL_SUCCESS == mca_common_monitoring_get_world_rank(i, data->p_comm->c_remote_group, &world_rank) ) - pos += sprintf(&tmp_procs[pos], "%d,", world_rank); + pos += snprintf(&tmp_procs[pos], bufsize - pos, "%d,", world_rank); } tmp_procs[pos - 1] = '\0'; /* Remove final coma */ data->procs = realloc(tmp_procs, pos * sizeof(char)); /* Adjust to size required */ diff --git a/ompi/mca/hook/comm_method/hook_comm_method_fns.c b/ompi/mca/hook/comm_method/hook_comm_method_fns.c index b1ab8c200b3..aad18b88608 100644 --- a/ompi/mca/hook/comm_method/hook_comm_method_fns.c +++ b/ompi/mca/hook/comm_method/hook_comm_method_fns.c @@ -325,9 +325,9 @@ abbreviate_list_into_string(char *str, int max, int *list, int nlist) strcpy(&str[strlen(str)], ", "); } if (lo != hi) { - sprintf(&str[strlen(str)], "%d - %d", lo, hi); + snprintf(&str[strlen(str)], max - strlen(str), "%d - %d", lo, hi); } else { - sprintf(&str[strlen(str)], "%d", lo); + snprintf(&str[strlen(str)], max - strlen(str), "%d", lo); } } /* @@ -352,9 +352,9 @@ abbreviate_list_into_string(char *str, int max, int *list, int nlist) strcpy(&str[strlen(str)], ", "); } if (lo != hi) { - sprintf(&str[strlen(str)], "%d - %d", lo, hi); + snprintf(&str[strlen(str)], max - strlen(str), "%d - %d", lo, hi); } else { - sprintf(&str[strlen(str)], "%d", lo); + snprintf(&str[strlen(str)], max - strlen(str), "%d", lo); } } } @@ -460,7 +460,7 @@ ompi_report_comm_methods(int called_from_location) len = strlen(opal_process_info.nodename) + 100; hoststring = malloc(len + 1); - sprintf(hoststring, "Host %d [%s] ranks ", + snprintf(hoststring, len + 1, "Host %d [%s] ranks ", myleaderrank, opal_process_info.nodename); abbreviate_list_into_string(&hoststring[strlen(hoststring)], @@ -642,7 +642,7 @@ ompi_report_comm_methods(int called_from_location) // 2: 2d table if (nleaderranks <= max2Dprottable) { char *str, *p; - int tmp, per, has_ucx_transport; + int tmp, per, has_ucx_transport, bufsize; int strlens[NUM_COMM_METHODS]; // characters per entry in the 2d table, must be large enough @@ -668,11 +668,11 @@ ompi_report_comm_methods(int called_from_location) if (tmp+1 > per) { per = tmp+1; } } } - - str = malloc(nleaderranks * per + 1); + bufsize = nleaderranks * per + 1; + str = malloc(bufsize); p = str; for (i=0; i 0) { // if (!first) { // strcat(str, " /"); // } - sprintf(&str[strlen(str)], + snprintf(&str[strlen(str)], + 1024 - strlen(str), " [%dx %s]", method_count[k], comm_method_to_string(k)); diff --git a/ompi/mca/sharedfp/lockedfile/sharedfp_lockedfile.c b/ompi/mca/sharedfp/lockedfile/sharedfp_lockedfile.c index cbeedd12c34..bfbc940ae11 100644 --- a/ompi/mca/sharedfp/lockedfile/sharedfp_lockedfile.c +++ b/ompi/mca/sharedfp/lockedfile/sharedfp_lockedfile.c @@ -117,7 +117,7 @@ struct mca_sharedfp_base_module_2_0_0_t * mca_sharedfp_lockedfile_component_file /* Set the filename. */ /*data filename created by appending .locktest.$rank to the original filename*/ - sprintf(filename,"%s%s%d",fh->f_filename,".locktest.",rank); + snprintf(filename, sizeof(filename), "%s%s%d",fh->f_filename,".locktest.",rank); lock.l_type = F_WRLCK; lock.l_start = 0; diff --git a/opal/mca/btl/smcuda/btl_smcuda.c b/opal/mca/btl/smcuda/btl_smcuda.c index c4389d422f2..1ce2b966ece 100644 --- a/opal/mca/btl/smcuda/btl_smcuda.c +++ b/opal/mca/btl/smcuda/btl_smcuda.c @@ -486,7 +486,7 @@ static struct mca_btl_base_endpoint_t *create_sm_endpoint(int local_proc, struct OBJ_CONSTRUCT(&ep->pending_sends, opal_list_t); OBJ_CONSTRUCT(&ep->endpoint_lock, opal_mutex_t); #if OPAL_ENABLE_PROGRESS_THREADS == 1 - sprintf(path, "%s" OPAL_PATH_SEP "sm_fifo.%lu", opal_process_info.job_session_dir, + snprintf(path, sizeof(path), "%s" OPAL_PATH_SEP "sm_fifo.%lu", opal_process_info.job_session_dir, (unsigned long) proc->proc_name); ep->fifo_fd = open(path, O_WRONLY); if (ep->fifo_fd < 0) { diff --git a/opal/mca/btl/smcuda/btl_smcuda_component.c b/opal/mca/btl/smcuda/btl_smcuda_component.c index 72b75d67311..8f633d6b48a 100644 --- a/opal/mca/btl/smcuda/btl_smcuda_component.c +++ b/opal/mca/btl/smcuda/btl_smcuda_component.c @@ -859,8 +859,9 @@ mca_btl_smcuda_component_init(int *num_btls, bool enable_progress_threads, bool #if OPAL_ENABLE_PROGRESS_THREADS == 1 /* create a named pipe to receive events */ - sprintf(mca_btl_smcuda_component.sm_fifo_path, "%s" OPAL_PATH_SEP "sm_fifo.%lu", - opal_process_info.job_session_dir, (unsigned long) OPAL_PROC_MY_NAME->vpid); + snprintf(mca_btl_smcuda_component.sm_fifo_path, sizeof(mca_btl_smcuda_component.sm_fifo_path), + "%s" OPAL_PATH_SEP "sm_fifo.%lu", + opal_process_info.job_session_dir, (unsigned long) OPAL_PROC_MY_NAME->vpid); if (mkfifo(mca_btl_smcuda_component.sm_fifo_path, 0660) < 0) { opal_output(0, "mca_btl_smcuda_component_init: mkfifo failed with errno=%d\n", errno); return NULL; diff --git a/opal/mca/btl/tcp/btl_tcp_component.c b/opal/mca/btl/tcp/btl_tcp_component.c index 39715729c96..41d8a5c162b 100644 --- a/opal/mca/btl/tcp/btl_tcp_component.c +++ b/opal/mca/btl/tcp/btl_tcp_component.c @@ -562,12 +562,12 @@ static int mca_btl_tcp_create(const int if_kindex, const char *if_name) btl->tcp_ifmask = selected_interface->if_mask; /* allow user to specify interface bandwidth */ - sprintf(param, "bandwidth_%s", if_name); + snprintf(param, sizeof(param), "bandwidth_%s", if_name); mca_btl_tcp_param_register_uint(param, NULL, btl->super.btl_bandwidth, OPAL_INFO_LVL_5, &btl->super.btl_bandwidth); /* allow user to override/specify latency ranking */ - sprintf(param, "latency_%s", if_name); + snprintf(param, sizeof(param), "latency_%s", if_name); mca_btl_tcp_param_register_uint(param, NULL, btl->super.btl_latency, OPAL_INFO_LVL_5, &btl->super.btl_latency); if (i > 0) { @@ -576,12 +576,12 @@ static int mca_btl_tcp_create(const int if_kindex, const char *if_name) } /* allow user to specify interface bandwidth */ - sprintf(param, "bandwidth_%s:%d", if_name, i); + snprintf(param, sizeof(param), "bandwidth_%s:%d", if_name, i); mca_btl_tcp_param_register_uint(param, NULL, btl->super.btl_bandwidth, OPAL_INFO_LVL_5, &btl->super.btl_bandwidth); /* allow user to override/specify latency ranking */ - sprintf(param, "latency_%s:%d", if_name, i); + snprintf(param, sizeof(param), "latency_%s:%d", if_name, i); mca_btl_tcp_param_register_uint(param, NULL, btl->super.btl_latency, OPAL_INFO_LVL_5, &btl->super.btl_latency); diff --git a/opal/util/timings.h b/opal/util/timings.h index 6dfc2ef6440..76aa7373124 100644 --- a/opal/util/timings.h +++ b/opal/util/timings.h @@ -60,7 +60,8 @@ void opal_timing_disable_native_timers(void); if (n > OPAL_TIMING_STR_LEN) { \ (_nm)->error = 1; \ } \ - n = sprintf((_nm)->cntr_env, "OMPI_TIMING_%s_CNT", (_nm)->id); \ + n = snprintf((_nm)->cntr_env, OPAL_TIMING_STR_LEN, \ + "OMPI_TIMING_%s_CNT", (_nm)->id); \ if (n > OPAL_TIMING_STR_LEN) { \ (_nm)->error = 1; \ } \ @@ -135,7 +136,7 @@ void opal_timing_disable_native_timers(void); } \ setenv(buf1, buf2, 1); \ h->cntr++; \ - sprintf(buf1, "%d", h->cntr); \ + snprintf(buf1, OPAL_TIMING_STR_LEN, "%d", h->cntr); \ setenv(h->cntr_env, buf1, 1); \ /* We don't include env operations into the consideration. \ * Hopefully this will help to make measurements more accurate. \ @@ -187,19 +188,19 @@ void opal_timing_disable_native_timers(void); } \ } while (0) -# define OPAL_TIMING_ENV_GETDESC_PREFIX(prefix, filename, func, i, desc, _t) \ - do { \ - char vname[OPAL_TIMING_STR_LEN]; \ - (_t) = 0.0; \ - sprintf(vname, "OMPI_TIMING_%s_%s_FILE_%d", prefix, func, i); \ - *filename = getenv(vname); \ - sprintf(vname, "OMPI_TIMING_%s_%s_DESC_%d", prefix, func, i); \ - *desc = getenv(vname); \ - sprintf(vname, "OMPI_TIMING_%s_%s_VAL_%d", prefix, func, i); \ - char *ptr = getenv(vname); \ - if (NULL != ptr) { \ - sscanf(ptr, "%lf", &(_t)); \ - } \ +# define OPAL_TIMING_ENV_GETDESC_PREFIX(prefix, filename, func, i, desc, _t) \ + do { \ + char vname[OPAL_TIMING_STR_LEN]; \ + (_t) = 0.0; \ + snprintf(vname, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_%s_FILE_%d", prefix, func, i); \ + *filename = getenv(vname); \ + snprintf(vname, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_%s_DESC_%d", prefix, func, i); \ + *desc = getenv(vname); \ + snprintf(vname, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_%s_VAL_%d", prefix, func, i); \ + char *ptr = getenv(vname); \ + if (NULL != ptr) { \ + sscanf(ptr, "%lf", &(_t)); \ + } \ } while (0) # define OPAL_TIMING_ENV_GETDESC(file, func, index, desc) \ diff --git a/test/datatype/position.c b/test/datatype/position.c index 94809e07a10..bd4f2834833 100644 --- a/test/datatype/position.c +++ b/test/datatype/position.c @@ -201,9 +201,9 @@ static char *bytes_dump(void *src, size_t cnt) static char text[1024]; int index, i; - index = sprintf(text, "0x"); + index = snprintf(text, sizeof(text), "0x"); for (i = 0; i < (int) cnt; i++) - index += sprintf(text + index, "%x", (int) (((char *) src)[i])); + index += snprintf(text + index, sizeof(text) - index, "%x", (int) (((char *) src)[i])); *(text + index) = '\0'; return text; } diff --git a/test/simple/crisscross.c b/test/simple/crisscross.c index 0f2f544ebb0..36378d49963 100644 --- a/test/simple/crisscross.c +++ b/test/simple/crisscross.c @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) mpierr = MPI_Get_processor_name(process_name, &count); if (mpierr != MPI_SUCCESS) { fprintf(stderr, "MPI Error %d (MPI_Get_processor_name) [%d]\n", mpierr, rank); - sprintf(process_name, "%s", rr_empty); + snprintf(process_name, sizeof(process_name), "%s", rr_empty); } else { if (count < MAX_RR_NAME) strncat(&process_name[count], rr_blank, MAX_RR_NAME - count); diff --git a/test/simple/no-disconnect.c b/test/simple/no-disconnect.c index d493a1bd946..6c3c6796a7a 100644 --- a/test/simple/no-disconnect.c +++ b/test/simple/no-disconnect.c @@ -162,7 +162,7 @@ int main(int argc, char **argv) printf("level = %d\n", level); /* prepare send buffer */ - sprintf(bufs, "level %d (pid:%d)", level, getpid()); + snprintf(bufs, sizeof(bufs), "level %d (pid:%d)", level, getpid()); /* spawn */ if (level < max_depth) { diff --git a/test/simple/parallel_r64.c b/test/simple/parallel_r64.c index 7ca5219417f..31460dd924f 100644 --- a/test/simple/parallel_r64.c +++ b/test/simple/parallel_r64.c @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) } } if (MPI_Get_processor_name(process_name, &count) != MPI_SUCCESS) { - sprintf(process_name, "%s", rr_empty); + snprintf(process_name, sizeof(process_name), "%s", rr_empty); } else { if (count < MAX_RR_NAME) strncat(&process_name[count], rr_blank, MAX_RR_NAME - count); diff --git a/test/simple/parallel_r8.c b/test/simple/parallel_r8.c index b8541e17ed5..239ba26a574 100644 --- a/test/simple/parallel_r8.c +++ b/test/simple/parallel_r8.c @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) } } if (MPI_Get_processor_name(process_name, &count) != MPI_SUCCESS) { - sprintf(process_name, "%s", rr_empty); + snprintf(process_name, sizeof(process_name), "%s", rr_empty); } else { if (count < MAX_RR_NAME) strncat(&process_name[count], rr_blank, MAX_RR_NAME - count); diff --git a/test/simple/parallel_w64.c b/test/simple/parallel_w64.c index fdb9acdd29c..90210ca9ff7 100644 --- a/test/simple/parallel_w64.c +++ b/test/simple/parallel_w64.c @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) } } if (MPI_Get_processor_name(process_name, &count) != MPI_SUCCESS) { - sprintf(process_name, "%s", rr_empty); + snprintf(process_name, sizeof(process_name), "%s", rr_empty); } else { if (count < MAX_RR_NAME) strncat(&process_name[count], rr_blank, MAX_RR_NAME - count); diff --git a/test/simple/parallel_w8.c b/test/simple/parallel_w8.c index 87eb41f6968..1b933c75b68 100644 --- a/test/simple/parallel_w8.c +++ b/test/simple/parallel_w8.c @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) } } if (MPI_Get_processor_name(process_name, &count) != MPI_SUCCESS) { - sprintf(process_name, "%s", rr_empty); + snprintf(process_name, sizeof(process_name), "%s", rr_empty); } else { if (count < MAX_RR_NAME) strncat(&process_name[count], rr_blank, MAX_RR_NAME - count); diff --git a/test/support/support.h b/test/support/support.h index a7249ff535b..8c2062ea978 100644 --- a/test/support/support.h +++ b/test/support/support.h @@ -47,15 +47,15 @@ void test_fail_stop(const char *msg, int status); * test_verify: Non-fatal assertion macro. */ -#define test_verify(MESSAGE, EXPR) \ - do { \ - if (!(EXPR)) { \ - char s[256]; \ - sprintf(s, "%s:%d: %s: %s\n", __FILE__, __LINE__, MESSAGE, #EXPR); \ - test_failure(s); \ - } else { \ - test_success(); \ - } \ +#define test_verify(MESSAGE, EXPR) \ + do { \ + if (!(EXPR)) { \ + char s[256]; \ + snprintf(s, sizeof(s), "%s:%d: %s: %s\n", __FILE__, __LINE__, MESSAGE, #EXPR); \ + test_failure(s); \ + } else { \ + test_success(); \ + } \ } while (0) #endif /* OMPI_SUPPORT_H */ From fa2d6e0cbf27baf3278b2bfa4b1a8159afc89c30 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Sat, 25 Oct 2025 11:36:32 -0400 Subject: [PATCH 2/8] acoll: remove unused module variables Signed-off-by: Joseph Schuchart --- ompi/mca/coll/acoll/coll_acoll_barrier.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/ompi/mca/coll/acoll/coll_acoll_barrier.c b/ompi/mca/coll/acoll/coll_acoll_barrier.c index 2398053191b..02f3a6500cb 100644 --- a/ompi/mca/coll/acoll/coll_acoll_barrier.c +++ b/ompi/mca/coll/acoll/coll_acoll_barrier.c @@ -119,7 +119,6 @@ int mca_coll_acoll_barrier_shm_h(struct ompi_communicator_t *comm, mca_coll_base int root = 0; int rank = ompi_comm_rank(comm); int size = ompi_comm_size(comm); - mca_coll_acoll_module_t *acoll_module = (mca_coll_acoll_module_t *) module; coll_acoll_init(module, comm, subc->data, subc, root); coll_acoll_data_t *data = subc->data; @@ -227,7 +226,6 @@ int mca_coll_acoll_barrier_shm_f(struct ompi_communicator_t *comm, mca_coll_base int root = 0; int rank = ompi_comm_rank(comm); int size = ompi_comm_size(comm); - mca_coll_acoll_module_t *acoll_module = (mca_coll_acoll_module_t *) module; coll_acoll_init(module, comm, subc->data, subc, root); coll_acoll_data_t *data = subc->data; From bfee6d719893fa8af55450360407f68f0f127165 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Sat, 25 Oct 2025 11:37:20 -0400 Subject: [PATCH 3/8] comm_cid: initialize remote_cid64 Clang warns about possible uninitialized use. Signed-off-by: Joseph Schuchart --- ompi/communicator/comm_cid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ompi/communicator/comm_cid.c b/ompi/communicator/comm_cid.c index 22967d3dfb4..5029e43da73 100644 --- a/ompi/communicator/comm_cid.c +++ b/ompi/communicator/comm_cid.c @@ -1066,7 +1066,7 @@ int ompi_comm_get_remote_cid_from_pmix (ompi_communicator_t *comm, int dest, uin pmix_value_t *val = NULL; ompi_comm_extended_cid_t excid; int rc = OMPI_SUCCESS; - size_t remote_cid64; + size_t remote_cid64 = 0; assert(NULL != remote_cid); From 296713cc6d5c106cc8e3353a91ab9c4db98eec09 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Sat, 25 Oct 2025 11:37:41 -0400 Subject: [PATCH 4/8] comm_cid: fix printf warnings Signed-off-by: Joseph Schuchart --- ompi/communicator/comm_cid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ompi/communicator/comm_cid.c b/ompi/communicator/comm_cid.c index 5029e43da73..822841ffb6c 100644 --- a/ompi/communicator/comm_cid.c +++ b/ompi/communicator/comm_cid.c @@ -1082,7 +1082,7 @@ int ompi_comm_get_remote_cid_from_pmix (ompi_communicator_t *comm, int dest, uin PMIX_INFO_LOAD(&tinfo[1], PMIX_GROUP_CONTEXT_ID, &excid.cid_base, PMIX_SIZE); PMIX_INFO_SET_QUALIFIER(&tinfo[1]); if (PMIX_SUCCESS != (rc = PMIx_Get(&pmix_proc, PMIX_GROUP_LOCAL_CID, tinfo, 2, &val))) { - OPAL_OUTPUT_VERBOSE((10, ompi_comm_output, "PMIx_Get failed for PMIX_GROUP_LOCAL_CID cid_base %ld %s", excid.cid_base, PMIx_Error_string(rc))); + OPAL_OUTPUT_VERBOSE((10, ompi_comm_output, "PMIx_Get failed for PMIX_GROUP_LOCAL_CID cid_base %llu %s", excid.cid_base, PMIx_Error_string(rc))); rc = OMPI_ERR_NOT_FOUND; goto done; } @@ -1103,7 +1103,7 @@ int ompi_comm_get_remote_cid_from_pmix (ompi_communicator_t *comm, int dest, uin rc = OMPI_SUCCESS; *remote_cid = (uint32_t)remote_cid64; comm->c_index_vec[dest] = (uint32_t)remote_cid64; - OPAL_OUTPUT_VERBOSE((10, ompi_comm_output, "PMIx_Get PMIX_GROUP_LOCAL_CID %d for cid_base %ld", *remote_cid, excid.cid_base)); + OPAL_OUTPUT_VERBOSE((10, ompi_comm_output, "PMIx_Get PMIX_GROUP_LOCAL_CID %d for cid_base %llu", *remote_cid, excid.cid_base)); done: if (NULL != val) { From 2fbeaa73437b1d0b5dcbf0311b68eef39dc6c6f1 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Sat, 25 Oct 2025 19:10:12 -0400 Subject: [PATCH 5/8] reduce-local: add parans around min/max macro The expression `max_k < min(a, b)` may not produce what we think it does. Signed-off-by: Joseph Schuchart --- test/datatype/reduce_local.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/datatype/reduce_local.c b/test/datatype/reduce_local.c index 9f1c06d4ba0..42fdb3e05c3 100644 --- a/test/datatype/reduce_local.c +++ b/test/datatype/reduce_local.c @@ -59,9 +59,9 @@ static int do_ops[12] = { static int verbose = 0; static int total_errors = 0; -#define max(a, b) (a) > (b) ? (a) : (b) +#define max(a, b) ((a) > (b) ? (a) : (b)) -#define min(a, b) (a) < (b) ? (a) : (b) +#define min(a, b) ((a) < (b) ? (a) : (b)) static void print_status(char *op, char *type, int type_size, int count, int max_shift, double *duration, int repeats, int correct) From 67ccb231f8edcf8cb2901a99be31f241e18b88a2 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Sat, 25 Oct 2025 19:15:05 -0400 Subject: [PATCH 6/8] Make _ucount int instead of size_t in mpi_image_info The struct stores offsets in a struct so there is no reason why this should be size_t. The compiler warns about a comparison `<0` for size_t in `ompi_field_offset`. Signed-off-by: Joseph Schuchart --- ompi/debuggers/ompi_common_dll_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ompi/debuggers/ompi_common_dll_defs.h b/ompi/debuggers/ompi_common_dll_defs.h index 5fe11d3986e..5e8fa9f814e 100644 --- a/ompi/debuggers/ompi_common_dll_defs.h +++ b/ompi/debuggers/ompi_common_dll_defs.h @@ -247,7 +247,7 @@ typedef struct int MPI_TAG; int MPI_ERROR; int _cancelled; - size_t _ucount; + int _ucount; } offset; } ompi_status_public_t; /* datatype structure */ From f298795bf28c7a112718bd02ca3a1852292681f9 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Sat, 25 Oct 2025 19:18:53 -0400 Subject: [PATCH 7/8] Use PRIu64 for uint64_t Signed-off-by: Joseph Schuchart --- ompi/communicator/comm_cid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ompi/communicator/comm_cid.c b/ompi/communicator/comm_cid.c index 822841ffb6c..be99de913ab 100644 --- a/ompi/communicator/comm_cid.c +++ b/ompi/communicator/comm_cid.c @@ -1082,7 +1082,7 @@ int ompi_comm_get_remote_cid_from_pmix (ompi_communicator_t *comm, int dest, uin PMIX_INFO_LOAD(&tinfo[1], PMIX_GROUP_CONTEXT_ID, &excid.cid_base, PMIX_SIZE); PMIX_INFO_SET_QUALIFIER(&tinfo[1]); if (PMIX_SUCCESS != (rc = PMIx_Get(&pmix_proc, PMIX_GROUP_LOCAL_CID, tinfo, 2, &val))) { - OPAL_OUTPUT_VERBOSE((10, ompi_comm_output, "PMIx_Get failed for PMIX_GROUP_LOCAL_CID cid_base %llu %s", excid.cid_base, PMIx_Error_string(rc))); + OPAL_OUTPUT_VERBOSE((10, ompi_comm_output, "PMIx_Get failed for PMIX_GROUP_LOCAL_CID cid_base %"PRIu64" %s", excid.cid_base, PMIx_Error_string(rc))); rc = OMPI_ERR_NOT_FOUND; goto done; } @@ -1103,7 +1103,7 @@ int ompi_comm_get_remote_cid_from_pmix (ompi_communicator_t *comm, int dest, uin rc = OMPI_SUCCESS; *remote_cid = (uint32_t)remote_cid64; comm->c_index_vec[dest] = (uint32_t)remote_cid64; - OPAL_OUTPUT_VERBOSE((10, ompi_comm_output, "PMIx_Get PMIX_GROUP_LOCAL_CID %d for cid_base %llu", *remote_cid, excid.cid_base)); + OPAL_OUTPUT_VERBOSE((10, ompi_comm_output, "PMIx_Get PMIX_GROUP_LOCAL_CID %d for cid_base %"PRIu64, *remote_cid, excid.cid_base)); done: if (NULL != val) { From c9ba52439912bd2b1cc5ddb26d7d3ef7601b7d83 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Sat, 25 Oct 2025 19:19:19 -0400 Subject: [PATCH 8/8] Name buffer size in ompi_report_comm_methods Signed-off-by: Joseph Schuchart --- ompi/mca/hook/comm_method/hook_comm_method_fns.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ompi/mca/hook/comm_method/hook_comm_method_fns.c b/ompi/mca/hook/comm_method/hook_comm_method_fns.c index aad18b88608..565fa85919c 100644 --- a/ompi/mca/hook/comm_method/hook_comm_method_fns.c +++ b/ompi/mca/hook/comm_method/hook_comm_method_fns.c @@ -973,9 +973,9 @@ ompi_report_comm_methods(int called_from_location) } } if (is_nonconformist) { - char *str = malloc(1024); -// int first = 1; - snprintf(str, 1024, " host %d:", i); + const size_t bufsize = 1024; + char *str = malloc(bufsize); + snprintf(str, bufsize, " host %d:", i); for (k=0; k 0) { // if (!first) {