Skip to content

Commit d4d5ff3

Browse files
committed
Fix misc. compiler warnings.
Found with gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1). - cmd_line.c:579: warning: ‘strncat’ output may be truncated copying 151 bytes from a string of length 151 [-Wstringop-truncation] - hwloc_base_util.c:1050: warning: ‘strncat’ output may be truncated copying between 0 and 8191 bytes from a string of length 8191 [-Wstringop-truncation] - base/hwloc_base_util.c:1077: warning: ‘strncat’ output may be truncated copying between 0 and 8191 bytes from a string of length 8191 [-Wstringop-truncation] - base/mpool_base_alloc.c:81: warning: comparison of integer expressions of different signedness: ‘ssize_t’ {aka ‘long int’} and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare] - mpiext_affinity_str.c:200: warning: ‘strncat’ output may be truncated copying between 0 and 1024 bytes from a string of length 8191 [-Wstringop-truncation] - mpiext_affinity_str.c:235: warning: ‘strncat’ output may be truncated copying between 0 and 1024 bytes from a string of length 8191 [-Wstringop-truncation] - mpiext_affinity_str.c:251: warning: ‘strncat’ output may be truncated copying between 0 and 1024 bytes from a string of length 8191 [-Wstringop-truncation] - mpiext_affinity_str.c:273: warning: ‘strncat’ output may be truncated copying between 0 and 1024 bytes from a string of length 8191 [-Wstringop-truncation] - mpiext_affinity_str.c:226: warning: ‘strncat’ output may be truncated copying between 0 and 1024 bytes from a string of length 8191 [-Wstringop-truncation] - hook_comm_method_fns.c:32: warning: ‘strncpy’ output may be truncated copying 15 bytes from a string of length 63 [-Wstringop-truncation] - osc_sm_component.c:224:32: warning: comparison of integer expressions of different signedness: ‘long unsigned int’ and ‘ssize_t’ {aka ‘long int’} [-Wsign-compare] - osc_sm_component.c:262:16: warning: declaration of ‘flag’ shadows a previous local [-Wshadow] - osc_sm_component.c:413:13: warning: declaration of ‘flag’ shadows a previous local [-Wshadow] - osc_rdma_component.c:1371: warning: comparison of integer expressions of different signedness: ‘long unsigned int’ and ‘ssize_t’ {aka ‘long int’} [-Wsign-compare] - osc_rdma_component.c:1325: warning: unused variable ‘infoval’ [-Wunused-variable] - dpm/dpm.c:667: warning: ‘modifiers’ may be used uninitialized in this function [-Wmaybe-uninitialized] - Cleanup: Move common code to osc/base. Signed-off-by: Austen Lauria <awlauria@us.ibm.com>
1 parent 7c9ab0a commit d4d5ff3

File tree

10 files changed

+33
-38
lines changed

10 files changed

+33
-38
lines changed

ompi/dpm/dpm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ static int dpm_convert(opal_list_t *infos,
690690
char *ck, *ptr, *help_str = NULL;
691691
int rc;
692692
char **tmp;
693-
dpm_conflicts_t *modifiers;
693+
dpm_conflicts_t *modifiers = NULL;
694694
const char *attr;
695695

696696
/* pick the modifiers to be checked */

ompi/mca/hook/comm_method/hook_comm_method_fns.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,9 @@
2222
#include "ompi/mca/bml/base/base.h"
2323
#include "ompi/mca/mtl/base/base.h"
2424

25-
// In regular strncpy up to n bytes are copied, so if the 'to' buffer
26-
// was char string[16] and you called strncpy(string, , 16) you could
27-
// get 16 bytes of chars without a null. My preferred API is to let
28-
// n be the size of the buffer, and to let n-1 chars be copied, and
29-
// to guarantee null termination.
3025
static void
3126
mystrncpy(char *to, const char *from, int n) {
32-
strncpy(to, from, n-1);
33-
to[n-1] = 0;
27+
snprintf(to, n, "%s", from);
3428
}
3529

3630
// For converting comm_method strings to comm_method id# and back.

ompi/mca/osc/base/base.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ BEGIN_C_DECLS
3737
int ompi_osc_base_find_available(bool enable_progress_threads,
3838
bool enable_mpi_threads);
3939

40+
void ompi_osc_base_set_memory_alignment(struct opal_info_t *info,
41+
size_t *memory_alignment);
42+
4043
int ompi_osc_base_select(ompi_win_t *win,
4144
void **base,
4245
size_t size,

ompi/mca/osc/base/osc_base_frame.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "ompi/mca/mca.h"
2323
#include "opal/util/output.h"
2424
#include "opal/mca/base/base.h"
25-
25+
#include "opal/include/opal/align.h"
2626

2727
#include "ompi/mca/osc/osc.h"
2828
#include "ompi/mca/osc/base/base.h"
@@ -36,6 +36,24 @@
3636

3737
#include "ompi/mca/osc/base/static-components.h"
3838

39+
void
40+
ompi_osc_base_set_memory_alignment(struct opal_info_t *info,
41+
size_t *memory_alignment)
42+
{
43+
int flag;
44+
opal_cstring_t *align_info_str;
45+
46+
opal_info_get(info, "mpi_minimum_memory_alignment", &align_info_str, &flag);
47+
if (flag) {
48+
long long tmp_align = atoll(align_info_str->string);
49+
OBJ_RELEASE(align_info_str);
50+
if ((long long) OPAL_ALIGN_MIN < tmp_align) {
51+
*memory_alignment = tmp_align;
52+
}
53+
}
54+
}
55+
56+
3957
int
4058
ompi_osc_base_find_available(bool enable_progress_threads,
4159
bool enable_mpi_threads)

ompi/mca/osc/rdma/osc_rdma_component.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
#include "opal/util/arch.h"
4949
#include "opal/util/argv.h"
5050
#include "opal/util/printf.h"
51-
#include "opal/align.h"
5251
#include "opal/util/sys_limits.h"
5352
#if OPAL_CUDA_SUPPORT
5453
#include "opal/mca/common/cuda/common_cuda.h"
@@ -1321,8 +1320,6 @@ static int ompi_osc_rdma_component_select (struct ompi_win_t *win, void **base,
13211320
int world_size = ompi_comm_size (comm);
13221321
int init_limit = 256;
13231322
int ret;
1324-
int flag;
1325-
char infoval[32];
13261323
char *name;
13271324

13281325
/* the osc/sm component is the exclusive provider for support for shared
@@ -1363,15 +1360,7 @@ static int ompi_osc_rdma_component_select (struct ompi_win_t *win, void **base,
13631360
module->size = size;
13641361
module->memory_alignment = mca_osc_rdma_component.memory_alignment;
13651362
if (NULL != info) {
1366-
opal_cstring_t *align_info_str;
1367-
opal_info_get(info, "mpi_minimum_memory_alignment", &align_info_str, &flag);
1368-
if (flag) {
1369-
ssize_t tmp_align = atoll(align_info_str->string);
1370-
OBJ_RELEASE(align_info_str);
1371-
if (OPAL_ALIGN_MIN < tmp_align) {
1372-
module->memory_alignment = tmp_align;
1373-
}
1374-
}
1363+
ompi_osc_base_set_memory_alignment(info, &module->memory_alignment);
13751364
}
13761365

13771366
/* set the module so we properly cleanup */

ompi/mca/osc/sm/osc_sm_component.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "ompi/mca/osc/base/osc_base_obj_convert.h"
3030
#include "ompi/request/request.h"
3131
#include "opal/util/sys_limits.h"
32-
#include "opal/include/opal/align.h"
32+
#include "opal/align.h"
3333
#include "opal/util/info_subscriber.h"
3434
#include "opal/util/printf.h"
3535
#include "opal/mca/mpool/base/base.h"
@@ -196,7 +196,6 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
196196
int comm_size = ompi_comm_size (comm);
197197
bool unlink_needed = false;
198198
int ret = OMPI_ERROR;
199-
int flag;
200199
size_t memory_alignment = OPAL_ALIGN_MIN;
201200

202201
if (OMPI_SUCCESS != (ret = check_win_ok(comm, flavor))) {
@@ -216,15 +215,7 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
216215
if (OPAL_SUCCESS != ret) goto error;
217216

218217
if (NULL != info) {
219-
opal_cstring_t *align_info_str;
220-
ret = opal_info_get(info, "mpi_minimum_memory_alignment", &align_info_str, &flag);
221-
if (flag) {
222-
ssize_t tmp_align = atoll(align_info_str->string);
223-
OBJ_RELEASE(align_info_str);
224-
if (OPAL_ALIGN_MIN < tmp_align) {
225-
memory_alignment = tmp_align;
226-
}
227-
}
218+
ompi_osc_base_set_memory_alignment(info, &memory_alignment);
228219
}
229220

230221
/* fill in the function pointer part */

ompi/mpiext/affinity/c/mpiext_affinity_str.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static int get_rsrc_exists(char str[OMPI_AFFINITY_STRING_MAX])
182182
{
183183
bool first = true;
184184
int i, num_cores, num_pus;
185-
char tmp[BUFSIZ];
185+
char tmp[OMPI_AFFINITY_STRING_MAX];
186186
const int stmp = sizeof(tmp) - 1;
187187
hwloc_obj_t socket, core, c2;
188188

opal/mca/hwloc/base/hwloc_base_util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ static char *bitmap2rangestr(int bitmap)
10471047
} else {
10481048
snprintf(tmp, stmp, "%d-%d", range_start, range_end);
10491049
}
1050-
strncat(ret, tmp, sizeof(ret) - strlen(ret) - 1);
1050+
snprintf(ret + strlen(ret), BUFSIZ, "%s", tmp);
10511051

10521052
range_start = -999;
10531053
}
@@ -1074,7 +1074,7 @@ static char *bitmap2rangestr(int bitmap)
10741074
} else {
10751075
snprintf(tmp, stmp, "%d-%d", range_start, range_end);
10761076
}
1077-
strncat(ret, tmp, sizeof(ret) - strlen(ret) - 1);
1077+
snprintf(ret + strlen(ret), BUFSIZ, "%s", tmp);
10781078
}
10791079

10801080
return ret;

opal/mca/mpool/base/mpool_base_alloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void *mca_mpool_base_alloc(size_t size, opal_info_t *info, const char *hints)
6363
mca_mpool_base_module_t *mpool;
6464
void *mem = NULL;
6565
opal_cstring_t *align_info_str;
66-
size_t memory_alignment = OPAL_ALIGN_MIN;
66+
long long memory_alignment = OPAL_ALIGN_MIN;
6767

6868
mpool_tree_item = mca_mpool_base_tree_item_get();
6969
if (!mpool_tree_item) {
@@ -76,7 +76,7 @@ void *mca_mpool_base_alloc(size_t size, opal_info_t *info, const char *hints)
7676
&align_info_str, &flag);
7777

7878
if (flag) {
79-
ssize_t tmp_align = atoll(align_info_str->string);
79+
long long tmp_align = atoll(align_info_str->string);
8080
OBJ_RELEASE(align_info_str);
8181
if (tmp_align > memory_alignment) {
8282
memory_alignment = tmp_align;

opal/util/cmd_line.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ char *opal_cmd_line_get_usage_msg(opal_cmd_line_t *cmd)
499499
int argc;
500500
size_t j;
501501
char **argv;
502-
char *ret, temp[MAX_WIDTH * 2], line[MAX_WIDTH * 2];
502+
char *ret, temp[(MAX_WIDTH * 2) - 1], line[MAX_WIDTH * 2];
503503
char *start, *desc, *ptr;
504504
opal_list_item_t *item;
505505
ompi_cmd_line_option_t *option, **sorted;

0 commit comments

Comments
 (0)