From a85bad37df4b2ee4d2b2ac945b482b75246b8030 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Sat, 6 Oct 2018 20:40:17 -0700 Subject: [PATCH] orte: strncpy() -> opal_string_copy() Fairly straightforward conversion of strncpy() calls to opal_string_copy(). Signed-off-by: Jeff Squyres --- orte/mca/oob/tcp/oob_tcp_sendrecv.h | 9 +++++---- orte/mca/plm/rsh/plm_rsh_component.c | 6 +++--- orte/mca/rmaps/base/rmaps_base_map_job.c | 9 +++++---- orte/mca/snapc/full/snapc_full_global.c | 4 +++- orte/orted/orted_submit.c | 6 ++++-- orte/test/system/pmixtool.c | 6 ++++-- orte/util/attr.c | 5 ++++- orte/util/name_fns.c | 4 +++- 8 files changed, 31 insertions(+), 18 deletions(-) diff --git a/orte/mca/oob/tcp/oob_tcp_sendrecv.h b/orte/mca/oob/tcp/oob_tcp_sendrecv.h index 9412a4e0fd..e906c962a9 100644 --- a/orte/mca/oob/tcp/oob_tcp_sendrecv.h +++ b/orte/mca/oob/tcp/oob_tcp_sendrecv.h @@ -11,7 +11,7 @@ * All rights reserved. * Copyright (c) 2006-2013 Los Alamos National Security, LLC. * All rights reserved. - * Copyright (c) 2010-2013 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2010-2018 Cisco Systems, Inc. All rights reserved * Copyright (c) 2013-2017 Intel, Inc. All rights reserved. * $COPYRIGHT$ * @@ -26,6 +26,7 @@ #include "orte_config.h" #include "opal/class/opal_list.h" +#include "opal/util/string_copy.h" #include "orte/mca/rml/base/base.h" #include "orte/util/threads.h" @@ -109,7 +110,7 @@ OBJ_CLASS_DECLARATION(mca_oob_tcp_recv_t); _s->hdr.tag = (m)->tag; \ _s->hdr.seq_num = (m)->seq_num; \ if (NULL != (m)->routed) { \ - (void)strncpy(_s->hdr.routed, (m)->routed, \ + (void)opal_string_copy(_s->hdr.routed, (m)->routed, \ ORTE_MAX_RTD_SIZE); \ } \ /* point to the actual message */ \ @@ -157,7 +158,7 @@ OBJ_CLASS_DECLARATION(mca_oob_tcp_recv_t); _s->hdr.tag = (m)->tag; \ _s->hdr.seq_num = (m)->seq_num; \ if (NULL != (m)->routed) { \ - (void)strncpy(_s->hdr.routed, (m)->routed, \ + (void)opal_string_copy(_s->hdr.routed, (m)->routed, \ ORTE_MAX_RTD_SIZE); \ } \ /* point to the actual message */ \ @@ -202,7 +203,7 @@ OBJ_CLASS_DECLARATION(mca_oob_tcp_recv_t); _s->hdr.dst = (m)->hdr.dst; \ _s->hdr.type = MCA_OOB_TCP_USER; \ _s->hdr.tag = (m)->hdr.tag; \ - (void)strncpy(_s->hdr.routed, (m)->hdr.routed, \ + (void)opal_string_copy(_s->hdr.routed, (m)->hdr.routed, \ ORTE_MAX_RTD_SIZE); \ /* point to the actual message */ \ _s->data = (m)->data; \ diff --git a/orte/mca/plm/rsh/plm_rsh_component.c b/orte/mca/plm/rsh/plm_rsh_component.c index d9c19c527d..5c666de7c4 100644 --- a/orte/mca/plm/rsh/plm_rsh_component.c +++ b/orte/mca/plm/rsh/plm_rsh_component.c @@ -15,7 +15,7 @@ * Copyright (c) 2008-2009 Sun Microsystems, Inc. All rights reserved. * Copyright (c) 2010 Oracle and/or its affiliates. All rights * reserved. - * Copyright (c) 2009-2016 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2009-2018 Cisco Systems, Inc. All rights reserved * Copyright (c) 2011 IBM Corporation. All rights reserved. * Copyright (c) 2015-2018 Intel, Inc. All rights reserved. * $COPYRIGHT$ @@ -45,6 +45,7 @@ #include "opal/util/argv.h" #include "opal/util/basename.h" #include "opal/util/path.h" +#include "opal/util/string_copy.h" #include "orte/mca/state/state.h" #include "orte/util/name_fns.h" @@ -365,8 +366,7 @@ char **orte_plm_rsh_search(const char* agent_list, const char *path) if (NULL == path) { getcwd(cwd, OPAL_PATH_MAX); } else { - strncpy(cwd, path, OPAL_PATH_MAX - 1); - cwd[OPAL_PATH_MAX - 1] = '\0'; + opal_string_copy(cwd, path, OPAL_PATH_MAX); } if (NULL == agent_list) { lines = opal_argv_split(mca_plm_rsh_component.agent, ':'); diff --git a/orte/mca/rmaps/base/rmaps_base_map_job.c b/orte/mca/rmaps/base/rmaps_base_map_job.c index 1730e23b12..db66b405f1 100644 --- a/orte/mca/rmaps/base/rmaps_base_map_job.c +++ b/orte/mca/rmaps/base/rmaps_base_map_job.c @@ -9,7 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2011-2018 Cisco Systems, Inc. All rights reserved * Copyright (c) 2011-2012 Los Alamos National Security, LLC. * All rights reserved. * Copyright (c) 2014-2018 Intel, Inc. All rights reserved. @@ -29,6 +29,7 @@ #include "orte/mca/mca.h" #include "opal/util/output.h" +#include "opal/util/string_copy.h" #include "opal/mca/base/base.h" #include "opal/mca/hwloc/base/base.h" #include "opal/dss/dss.h" @@ -530,14 +531,14 @@ void orte_rmaps_base_display_map(orte_job_t *jdata) memset(tmp1, 0, sizeof(tmp1)); if (orte_get_attribute(&proc->attributes, ORTE_PROC_HWLOC_BOUND, (void**)&bd, OPAL_PTR)) { if (NULL == bd) { - (void)strncpy(tmp1, "UNBOUND", sizeof(tmp1)); + (void)opal_string_copy(tmp1, "UNBOUND", sizeof(tmp1)); } else { if (OPAL_ERR_NOT_BOUND == opal_hwloc_base_cset2mapstr(tmp1, sizeof(tmp1), node->topology->topo, bd->cpuset)) { - (void)strncpy(tmp1, "UNBOUND", sizeof(tmp1)); + (void)opal_string_copy(tmp1, "UNBOUND", sizeof(tmp1)); } } } else { - (void)strncpy(tmp1, "UNBOUND", sizeof(tmp1)); + (void)opal_string_copy(tmp1, "UNBOUND", sizeof(tmp1)); } opal_output(orte_clean_output, "\t\t", ORTE_VPID_PRINT(proc->name.vpid), (long)proc->app_idx, diff --git a/orte/mca/snapc/full/snapc_full_global.c b/orte/mca/snapc/full/snapc_full_global.c index 10d0419840..b5e0a5b753 100644 --- a/orte/mca/snapc/full/snapc_full_global.c +++ b/orte/mca/snapc/full/snapc_full_global.c @@ -9,6 +9,7 @@ * All rights reserved. * Copyright (c) 2007 Evergrid, Inc. All rights reserved. * + * Copyright (c) 2018 Cisco Systems, Inc. All rights reserved * $COPYRIGHT$ * * Additional copyrights may follow @@ -28,6 +29,7 @@ #include "opal/util/opal_environ.h" #include "opal/util/basename.h" #include "opal/util/show_help.h" +#include "opal/util/string_copy.h" #include "orte/mca/mca.h" #include "opal/mca/base/base.h" #include "opal/mca/crs/crs.h" @@ -1381,7 +1383,7 @@ static void snapc_full_process_request_op_cmd(orte_process_name_t* sender, ORTE_ERROR_LOG(ret); goto cleanup; } - strncpy( ((datum->mig_host_pref)[i]), tmp_str, OPAL_MAX_PROCESSOR_NAME); + opal_string_copy( ((datum->mig_host_pref)[i]), tmp_str, OPAL_MAX_PROCESSOR_NAME); count = 1; if (ORTE_SUCCESS != (ret = opal_dss.unpack(sbuffer, &((datum->mig_vpid_pref)[i]), &count, OPAL_INT))) { diff --git a/orte/orted/orted_submit.c b/orte/orted/orted_submit.c index 564a5a05cb..96d9866ce1 100644 --- a/orte/orted/orted_submit.c +++ b/orte/orted/orted_submit.c @@ -10,7 +10,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2006-2017 Cisco Systems, Inc. All rights reserved + * Copyright (c) 2006-2018 Cisco Systems, Inc. All rights reserved * Copyright (c) 2007-2009 Sun Microsystems, Inc. All rights reserved. * Copyright (c) 2007-2017 Los Alamos National Security, LLC. All rights * reserved. @@ -72,6 +72,7 @@ #include "opal/util/opal_getcwd.h" #include "opal/util/show_help.h" #include "opal/util/fd.h" +#include "opal/util/string_copy.h" #include "opal/sys/atomic.h" #if OPAL_ENABLE_FT_CR == 1 #include "opal/runtime/opal_cr.h" @@ -2295,7 +2296,8 @@ static void orte_debugger_init_before_spawn(orte_job_t *jdata) free(attach_fifo); return; } - strncpy(MPIR_attach_fifo, attach_fifo, MPIR_MAX_PATH_LENGTH - 1); + opal_string_copy(MPIR_attach_fifo, attach_fifo, + MPIR_MAX_PATH_LENGTH); free(attach_fifo); open_fifo(); } diff --git a/orte/test/system/pmixtool.c b/orte/test/system/pmixtool.c index 53e8c37d38..f809efe18e 100644 --- a/orte/test/system/pmixtool.c +++ b/orte/test/system/pmixtool.c @@ -11,7 +11,7 @@ * All rights reserved. * Copyright (c) 2006-2013 Los Alamos National Security, LLC. * All rights reserved. - * Copyright (c) 2009-2012 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2009-2018 Cisco Systems, Inc. All rights reserved * Copyright (c) 2011 Oak Ridge National Labs. All rights reserved. * Copyright (c) 2013-2016 Intel, Inc. All rights reserved. * Copyright (c) 2015 Mellanox Technologies, Inc. All rights reserved. @@ -28,6 +28,8 @@ #include #include +#include "opal/util/string_copy.h" + #include int main(int argc, char **argv) @@ -47,7 +49,7 @@ int main(int argc, char **argv) /* query something */ ninfo = 1; PMIX_INFO_CREATE(info, ninfo); - (void)strncpy(info[0].key, PMIX_QUERY_NAMESPACES, PMIX_MAX_KEYLEN); + (void)opal_string_copy(info[0].key, PMIX_QUERY_NAMESPACES, PMIX_MAX_KEYLEN); if (PMIX_SUCCESS != (rc = PMIx_Query_info(info, ninfo))) { fprintf(stderr, "Tool ns %s rank %d: PMIx_Query_info failed: %d\n", myproc.nspace, myproc.rank, rc); goto done; diff --git a/orte/util/attr.c b/orte/util/attr.c index 87047db7f5..483018e922 100644 --- a/orte/util/attr.c +++ b/orte/util/attr.c @@ -2,6 +2,7 @@ * Copyright (c) 2014-2018 Intel, Inc. All rights reserved. * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. + * Copyright (c) 2018 Cisco Systems, Inc. All rights reserved * $COPYRIGHT$ * * Additional copyrights may follow @@ -15,6 +16,7 @@ #include "opal/dss/dss.h" #include "opal/util/output.h" +#include "opal/util/string_copy.h" #include "orte/mca/errmgr/errmgr.h" @@ -187,7 +189,8 @@ int orte_attr_register(const char *project, for (i = 0 ; i < MAX_CONVERTERS ; ++i) { if (0 == converters[i].init) { converters[i].init = 1; - strncpy(converters[i].project, project, MAX_CONVERTER_PROJECT_LEN); + opal_string_copy(converters[i].project, project, + MAX_CONVERTER_PROJECT_LEN); converters[i].project[MAX_CONVERTER_PROJECT_LEN-1] = '\0'; converters[i].key_base = key_base; converters[i].key_max = key_max; diff --git a/orte/util/name_fns.c b/orte/util/name_fns.c index 4c91dfe121..7d5cd876d9 100644 --- a/orte/util/name_fns.c +++ b/orte/util/name_fns.c @@ -13,6 +13,7 @@ * Copyright (c) 2014-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2016-2018 Intel, Inc. All rights reserved. + * Copyright (c) 2018 Cisco Systems, Inc. All rights reserved * $COPYRIGHT$ * * Additional copyrights may follow @@ -27,6 +28,7 @@ #include #include "opal/util/printf.h" +#include "opal/util/string_copy.h" #include "opal/threads/tsd.h" #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 /* check for wildcard value - handle appropriately */ if (ORTE_JOBID_WILDCARD == jobid) { - (void)strncpy(jobid_string, ORTE_SCHEMA_WILDCARD_STRING, size); + (void)opal_string_copy(jobid_string, ORTE_SCHEMA_WILDCARD_STRING, size); } else { rc = snprintf(jobid_string, size, "%ld", (long) jobid); if (0 > rc) {