Skip to content

Commit a601c9a

Browse files
committed
hook comm_method: fix compiler warnings
1. Guarantee that strings are \0 by using opal_string_copy() 2. Ensure that a temporary string buffer is long enough to hold odd sprintf values for "%3d" (e.g., error values) Without these changes, gcc 14's static analyzer emitted warnings. Signed-off-by: Jeff Squyres <jeff@squyres.com>
1 parent 35f4a6d commit a601c9a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ompi/mca/hook/comm_method/hook_comm_method_fns.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2016-2022 IBM Corporation. All rights reserved.
3+
* Copyright (c) 2024 Jeffrey M. Squyres. All rights reserved.
34
* $COPYRIGHT$
45
*
56
* Additional copyrights may follow
@@ -15,6 +16,7 @@
1516
#include <dlfcn.h>
1617
#endif
1718

19+
#include "opal/util/string_copy.h"
1820
#include "ompi/communicator/communicator.h"
1921
#include "ompi/mca/pml/pml.h"
2022
#include "opal/mca/btl/btl.h"
@@ -105,21 +107,21 @@ comm_method_string(MPI_Comm comm, int rank, int *comm_mode) {
105107
if (comm_mode) { *comm_mode = MODE_IS_BTL; }
106108
btl = lookup_btl_name_for_send(comm, rank);
107109
if (NULL == btl) {
108-
strncpy(string, "n/a", COMM_METHOD_STRING_SIZE);
110+
opal_string_copy(string, "n/a", COMM_METHOD_STRING_SIZE);
109111
} else {
110-
strncpy(string, btl, COMM_METHOD_STRING_SIZE);
112+
opal_string_copy(string, btl, COMM_METHOD_STRING_SIZE);
111113
}
112114
}
113115
else if (p && 0==strncmp("cm", p, 3)) { // MTL
114116
if (comm_mode) { *comm_mode = MODE_IS_MTL; }
115-
strncpy(string, lookup_mtl_name(), COMM_METHOD_STRING_SIZE);
117+
opal_string_copy(string, lookup_mtl_name(), COMM_METHOD_STRING_SIZE);
116118
} else { // PML
117119
if (comm_mode) { *comm_mode = MODE_IS_PML; }
118120
if (p) {
119-
strncpy(string, p, COMM_METHOD_STRING_SIZE);
121+
opal_string_copy(string, p, COMM_METHOD_STRING_SIZE);
120122
}
121123
else {
122-
strncpy(string, "n/a", COMM_METHOD_STRING_SIZE);
124+
opal_string_copy(string, "n/a", COMM_METHOD_STRING_SIZE);
123125
}
124126
}
125127
}
@@ -695,7 +697,7 @@ ompi_report_comm_methods(int called_from_location)
695697
p = str;
696698
for (k=0; k<nleaderranks; ++k) {
697699
char *method_string;
698-
char ucx_label[10];
700+
char ucx_label[20];
699701

700702
method_string = comm_method_to_string(method[i * nleaderranks + k]);
701703
if (0 == strncmp(method_string, UCX_TAG, strlen(UCX_TAG))) {

0 commit comments

Comments
 (0)