Skip to content

Commit a85bad3

Browse files
committed
orte: strncpy() -> opal_string_copy()
Fairly straightforward conversion of strncpy() calls to opal_string_copy(). Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
1 parent cef6cf0 commit a85bad3

File tree

8 files changed

+31
-18
lines changed

8 files changed

+31
-18
lines changed

orte/mca/oob/tcp/oob_tcp_sendrecv.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* All rights reserved.
1212
* Copyright (c) 2006-2013 Los Alamos National Security, LLC.
1313
* All rights reserved.
14-
* Copyright (c) 2010-2013 Cisco Systems, Inc. All rights reserved.
14+
* Copyright (c) 2010-2018 Cisco Systems, Inc. All rights reserved
1515
* Copyright (c) 2013-2017 Intel, Inc. All rights reserved.
1616
* $COPYRIGHT$
1717
*
@@ -26,6 +26,7 @@
2626
#include "orte_config.h"
2727

2828
#include "opal/class/opal_list.h"
29+
#include "opal/util/string_copy.h"
2930

3031
#include "orte/mca/rml/base/base.h"
3132
#include "orte/util/threads.h"
@@ -109,7 +110,7 @@ OBJ_CLASS_DECLARATION(mca_oob_tcp_recv_t);
109110
_s->hdr.tag = (m)->tag; \
110111
_s->hdr.seq_num = (m)->seq_num; \
111112
if (NULL != (m)->routed) { \
112-
(void)strncpy(_s->hdr.routed, (m)->routed, \
113+
(void)opal_string_copy(_s->hdr.routed, (m)->routed, \
113114
ORTE_MAX_RTD_SIZE); \
114115
} \
115116
/* point to the actual message */ \
@@ -157,7 +158,7 @@ OBJ_CLASS_DECLARATION(mca_oob_tcp_recv_t);
157158
_s->hdr.tag = (m)->tag; \
158159
_s->hdr.seq_num = (m)->seq_num; \
159160
if (NULL != (m)->routed) { \
160-
(void)strncpy(_s->hdr.routed, (m)->routed, \
161+
(void)opal_string_copy(_s->hdr.routed, (m)->routed, \
161162
ORTE_MAX_RTD_SIZE); \
162163
} \
163164
/* point to the actual message */ \
@@ -202,7 +203,7 @@ OBJ_CLASS_DECLARATION(mca_oob_tcp_recv_t);
202203
_s->hdr.dst = (m)->hdr.dst; \
203204
_s->hdr.type = MCA_OOB_TCP_USER; \
204205
_s->hdr.tag = (m)->hdr.tag; \
205-
(void)strncpy(_s->hdr.routed, (m)->hdr.routed, \
206+
(void)opal_string_copy(_s->hdr.routed, (m)->hdr.routed, \
206207
ORTE_MAX_RTD_SIZE); \
207208
/* point to the actual message */ \
208209
_s->data = (m)->data; \

orte/mca/plm/rsh/plm_rsh_component.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Copyright (c) 2008-2009 Sun Microsystems, Inc. All rights reserved.
1616
* Copyright (c) 2010 Oracle and/or its affiliates. All rights
1717
* reserved.
18-
* Copyright (c) 2009-2016 Cisco Systems, Inc. All rights reserved.
18+
* Copyright (c) 2009-2018 Cisco Systems, Inc. All rights reserved
1919
* Copyright (c) 2011 IBM Corporation. All rights reserved.
2020
* Copyright (c) 2015-2018 Intel, Inc. All rights reserved.
2121
* $COPYRIGHT$
@@ -45,6 +45,7 @@
4545
#include "opal/util/argv.h"
4646
#include "opal/util/basename.h"
4747
#include "opal/util/path.h"
48+
#include "opal/util/string_copy.h"
4849

4950
#include "orte/mca/state/state.h"
5051
#include "orte/util/name_fns.h"
@@ -365,8 +366,7 @@ char **orte_plm_rsh_search(const char* agent_list, const char *path)
365366
if (NULL == path) {
366367
getcwd(cwd, OPAL_PATH_MAX);
367368
} else {
368-
strncpy(cwd, path, OPAL_PATH_MAX - 1);
369-
cwd[OPAL_PATH_MAX - 1] = '\0';
369+
opal_string_copy(cwd, path, OPAL_PATH_MAX);
370370
}
371371
if (NULL == agent_list) {
372372
lines = opal_argv_split(mca_plm_rsh_component.agent, ':');

orte/mca/rmaps/base/rmaps_base_map_job.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* University of Stuttgart. All rights reserved.
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
12-
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
12+
* Copyright (c) 2011-2018 Cisco Systems, Inc. All rights reserved
1313
* Copyright (c) 2011-2012 Los Alamos National Security, LLC.
1414
* All rights reserved.
1515
* Copyright (c) 2014-2018 Intel, Inc. All rights reserved.
@@ -29,6 +29,7 @@
2929

3030
#include "orte/mca/mca.h"
3131
#include "opal/util/output.h"
32+
#include "opal/util/string_copy.h"
3233
#include "opal/mca/base/base.h"
3334
#include "opal/mca/hwloc/base/base.h"
3435
#include "opal/dss/dss.h"
@@ -530,14 +531,14 @@ void orte_rmaps_base_display_map(orte_job_t *jdata)
530531
memset(tmp1, 0, sizeof(tmp1));
531532
if (orte_get_attribute(&proc->attributes, ORTE_PROC_HWLOC_BOUND, (void**)&bd, OPAL_PTR)) {
532533
if (NULL == bd) {
533-
(void)strncpy(tmp1, "UNBOUND", sizeof(tmp1));
534+
(void)opal_string_copy(tmp1, "UNBOUND", sizeof(tmp1));
534535
} else {
535536
if (OPAL_ERR_NOT_BOUND == opal_hwloc_base_cset2mapstr(tmp1, sizeof(tmp1), node->topology->topo, bd->cpuset)) {
536-
(void)strncpy(tmp1, "UNBOUND", sizeof(tmp1));
537+
(void)opal_string_copy(tmp1, "UNBOUND", sizeof(tmp1));
537538
}
538539
}
539540
} else {
540-
(void)strncpy(tmp1, "UNBOUND", sizeof(tmp1));
541+
(void)opal_string_copy(tmp1, "UNBOUND", sizeof(tmp1));
541542
}
542543
opal_output(orte_clean_output, "\t\t<process rank=%s app_idx=%ld local_rank=%lu node_rank=%lu binding=%s>",
543544
ORTE_VPID_PRINT(proc->name.vpid), (long)proc->app_idx,

orte/mca/snapc/full/snapc_full_global.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* All rights reserved.
1010
* Copyright (c) 2007 Evergrid, Inc. All rights reserved.
1111
*
12+
* Copyright (c) 2018 Cisco Systems, Inc. All rights reserved
1213
* $COPYRIGHT$
1314
*
1415
* Additional copyrights may follow
@@ -28,6 +29,7 @@
2829
#include "opal/util/opal_environ.h"
2930
#include "opal/util/basename.h"
3031
#include "opal/util/show_help.h"
32+
#include "opal/util/string_copy.h"
3133
#include "orte/mca/mca.h"
3234
#include "opal/mca/base/base.h"
3335
#include "opal/mca/crs/crs.h"
@@ -1381,7 +1383,7 @@ static void snapc_full_process_request_op_cmd(orte_process_name_t* sender,
13811383
ORTE_ERROR_LOG(ret);
13821384
goto cleanup;
13831385
}
1384-
strncpy( ((datum->mig_host_pref)[i]), tmp_str, OPAL_MAX_PROCESSOR_NAME);
1386+
opal_string_copy( ((datum->mig_host_pref)[i]), tmp_str, OPAL_MAX_PROCESSOR_NAME);
13851387

13861388
count = 1;
13871389
if (ORTE_SUCCESS != (ret = opal_dss.unpack(sbuffer, &((datum->mig_vpid_pref)[i]), &count, OPAL_INT))) {

orte/orted/orted_submit.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* University of Stuttgart. All rights reserved.
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
13-
* Copyright (c) 2006-2017 Cisco Systems, Inc. All rights reserved
13+
* Copyright (c) 2006-2018 Cisco Systems, Inc. All rights reserved
1414
* Copyright (c) 2007-2009 Sun Microsystems, Inc. All rights reserved.
1515
* Copyright (c) 2007-2017 Los Alamos National Security, LLC. All rights
1616
* reserved.
@@ -72,6 +72,7 @@
7272
#include "opal/util/opal_getcwd.h"
7373
#include "opal/util/show_help.h"
7474
#include "opal/util/fd.h"
75+
#include "opal/util/string_copy.h"
7576
#include "opal/sys/atomic.h"
7677
#if OPAL_ENABLE_FT_CR == 1
7778
#include "opal/runtime/opal_cr.h"
@@ -2295,7 +2296,8 @@ static void orte_debugger_init_before_spawn(orte_job_t *jdata)
22952296
free(attach_fifo);
22962297
return;
22972298
}
2298-
strncpy(MPIR_attach_fifo, attach_fifo, MPIR_MAX_PATH_LENGTH - 1);
2299+
opal_string_copy(MPIR_attach_fifo, attach_fifo,
2300+
MPIR_MAX_PATH_LENGTH);
22992301
free(attach_fifo);
23002302
open_fifo();
23012303
}

orte/test/system/pmixtool.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* All rights reserved.
1212
* Copyright (c) 2006-2013 Los Alamos National Security, LLC.
1313
* All rights reserved.
14-
* Copyright (c) 2009-2012 Cisco Systems, Inc. All rights reserved.
14+
* Copyright (c) 2009-2018 Cisco Systems, Inc. All rights reserved
1515
* Copyright (c) 2011 Oak Ridge National Labs. All rights reserved.
1616
* Copyright (c) 2013-2016 Intel, Inc. All rights reserved.
1717
* Copyright (c) 2015 Mellanox Technologies, Inc. All rights reserved.
@@ -28,6 +28,8 @@
2828
#include <unistd.h>
2929
#include <time.h>
3030

31+
#include "opal/util/string_copy.h"
32+
3133
#include <pmix_tool.h>
3234

3335
int main(int argc, char **argv)
@@ -47,7 +49,7 @@ int main(int argc, char **argv)
4749
/* query something */
4850
ninfo = 1;
4951
PMIX_INFO_CREATE(info, ninfo);
50-
(void)strncpy(info[0].key, PMIX_QUERY_NAMESPACES, PMIX_MAX_KEYLEN);
52+
(void)opal_string_copy(info[0].key, PMIX_QUERY_NAMESPACES, PMIX_MAX_KEYLEN);
5153
if (PMIX_SUCCESS != (rc = PMIx_Query_info(info, ninfo))) {
5254
fprintf(stderr, "Tool ns %s rank %d: PMIx_Query_info failed: %d\n", myproc.nspace, myproc.rank, rc);
5355
goto done;

orte/util/attr.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (c) 2014-2018 Intel, Inc. All rights reserved.
33
* Copyright (c) 2014-2017 Research Organization for Information Science
44
* and Technology (RIST). All rights reserved.
5+
* Copyright (c) 2018 Cisco Systems, Inc. All rights reserved
56
* $COPYRIGHT$
67
*
78
* Additional copyrights may follow
@@ -15,6 +16,7 @@
1516

1617
#include "opal/dss/dss.h"
1718
#include "opal/util/output.h"
19+
#include "opal/util/string_copy.h"
1820

1921
#include "orte/mca/errmgr/errmgr.h"
2022

@@ -187,7 +189,8 @@ int orte_attr_register(const char *project,
187189
for (i = 0 ; i < MAX_CONVERTERS ; ++i) {
188190
if (0 == converters[i].init) {
189191
converters[i].init = 1;
190-
strncpy(converters[i].project, project, MAX_CONVERTER_PROJECT_LEN);
192+
opal_string_copy(converters[i].project, project,
193+
MAX_CONVERTER_PROJECT_LEN);
191194
converters[i].project[MAX_CONVERTER_PROJECT_LEN-1] = '\0';
192195
converters[i].key_base = key_base;
193196
converters[i].key_max = key_max;

orte/util/name_fns.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Copyright (c) 2014-2016 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
1515
* Copyright (c) 2016-2018 Intel, Inc. All rights reserved.
16+
* Copyright (c) 2018 Cisco Systems, Inc. All rights reserved
1617
* $COPYRIGHT$
1718
*
1819
* Additional copyrights may follow
@@ -27,6 +28,7 @@
2728
#include <string.h>
2829

2930
#include "opal/util/printf.h"
31+
#include "opal/util/string_copy.h"
3032
#include "opal/threads/tsd.h"
3133

3234
#include "orte/mca/errmgr/errmgr.h"
@@ -292,7 +294,7 @@ int orte_util_snprintf_jobid(char *jobid_string, size_t size, const orte_jobid_t
292294

293295
/* check for wildcard value - handle appropriately */
294296
if (ORTE_JOBID_WILDCARD == jobid) {
295-
(void)strncpy(jobid_string, ORTE_SCHEMA_WILDCARD_STRING, size);
297+
(void)opal_string_copy(jobid_string, ORTE_SCHEMA_WILDCARD_STRING, size);
296298
} else {
297299
rc = snprintf(jobid_string, size, "%ld", (long) jobid);
298300
if (0 > rc) {

0 commit comments

Comments
 (0)