Skip to content

Commit 296c91a

Browse files
authored
Merge pull request #5918 from jsquyres/pr/strcpy-no-more
Cleanup some string operations
2 parents a5b1c9a + 54ca331 commit 296c91a

39 files changed

+245
-168
lines changed

ompi/communicator/comm.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2007-2011 University of Houston. All rights reserved.
14-
* Copyright (c) 2007-2012 Cisco Systems, Inc. All rights reserved.
14+
* Copyright (c) 2007-2018 Cisco Systems, Inc. All rights reserved
1515
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
1616
* Copyright (c) 2011-2013 Inria. All rights reserved.
1717
* Copyright (c) 2011-2013 Universite Bordeaux 1
@@ -38,6 +38,7 @@
3838
#include "opal/mca/hwloc/base/base.h"
3939
#include "opal/dss/dss.h"
4040
#include "opal/mca/pmix/pmix.h"
41+
#include "opal/util/string_copy.h"
4142

4243
#include "ompi/proc/proc.h"
4344
#include "opal/threads/mutex.h"
@@ -1317,9 +1318,7 @@ int ompi_comm_set_name (ompi_communicator_t *comm, const char *name )
13171318
{
13181319

13191320
OPAL_THREAD_LOCK(&(comm->c_lock));
1320-
memset(comm->c_name, 0, MPI_MAX_OBJECT_NAME);
1321-
strncpy(comm->c_name, name, MPI_MAX_OBJECT_NAME);
1322-
comm->c_name[MPI_MAX_OBJECT_NAME - 1] = 0;
1321+
opal_string_copy(comm->c_name, name, MPI_MAX_OBJECT_NAME);
13231322
comm->c_flags |= OMPI_COMM_NAMEISSET;
13241323
OPAL_THREAD_UNLOCK(&(comm->c_lock));
13251324

ompi/communicator/comm_init.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2006-2017 University of Houston. All rights reserved.
14-
* Copyright (c) 2007-2012 Cisco Systems, Inc. All rights reserved.
14+
* Copyright (c) 2007-2018 Cisco Systems, Inc. All rights reserved
1515
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
1616
* Copyright (c) 2012-2015 Los Alamos National Security, LLC.
1717
* All rights reserved.
@@ -35,6 +35,7 @@
3535

3636
#include "opal/util/bit_ops.h"
3737
#include "opal/util/info_subscriber.h"
38+
#include "opal/util/string_copy.h"
3839
#include "opal/mca/pmix/pmix.h"
3940
#include "ompi/constants.h"
4041
#include "ompi/mca/pml/pml.h"
@@ -139,9 +140,8 @@ int ompi_comm_init(void)
139140
OMPI_COMM_SET_PML_ADDED(&ompi_mpi_comm_world.comm);
140141
opal_pointer_array_set_item (&ompi_mpi_communicators, 0, &ompi_mpi_comm_world);
141142

142-
MEMCHECKER (memset (ompi_mpi_comm_world.comm.c_name, 0, MPI_MAX_OBJECT_NAME));
143-
strncpy (ompi_mpi_comm_world.comm.c_name, "MPI_COMM_WORLD",
144-
strlen("MPI_COMM_WORLD")+1 );
143+
opal_string_copy(ompi_mpi_comm_world.comm.c_name, "MPI_COMM_WORLD",
144+
sizeof(ompi_mpi_comm_world.comm.c_name));
145145
ompi_mpi_comm_world.comm.c_flags |= OMPI_COMM_NAMEISSET;
146146
ompi_mpi_comm_world.comm.c_flags |= OMPI_COMM_INTRINSIC;
147147

@@ -193,8 +193,8 @@ int ompi_comm_init(void)
193193
OMPI_COMM_SET_PML_ADDED(&ompi_mpi_comm_self.comm);
194194
opal_pointer_array_set_item (&ompi_mpi_communicators, 1, &ompi_mpi_comm_self);
195195

196-
MEMCHECKER (memset (ompi_mpi_comm_self.comm.c_name, 0, MPI_MAX_OBJECT_NAME));
197-
strncpy(ompi_mpi_comm_self.comm.c_name,"MPI_COMM_SELF",strlen("MPI_COMM_SELF")+1);
196+
opal_string_copy(ompi_mpi_comm_self.comm.c_name, "MPI_COMM_SELF",
197+
sizeof(ompi_mpi_comm_self.comm.c_name));
198198
ompi_mpi_comm_self.comm.c_flags |= OMPI_COMM_NAMEISSET;
199199
ompi_mpi_comm_self.comm.c_flags |= OMPI_COMM_INTRINSIC;
200200

@@ -218,8 +218,8 @@ int ompi_comm_init(void)
218218
OBJ_RETAIN( &ompi_mpi_errors_are_fatal.eh );
219219
opal_pointer_array_set_item (&ompi_mpi_communicators, 2, &ompi_mpi_comm_null);
220220

221-
MEMCHECKER (memset (ompi_mpi_comm_null.comm.c_name, 0, MPI_MAX_OBJECT_NAME));
222-
strncpy(ompi_mpi_comm_null.comm.c_name,"MPI_COMM_NULL",strlen("MPI_COMM_NULL")+1);
221+
opal_string_copy(ompi_mpi_comm_null.comm.c_name, "MPI_COMM_NULL",
222+
sizeof(ompi_mpi_comm_null.comm.c_name));
223223
ompi_mpi_comm_null.comm.c_flags |= OMPI_COMM_NAMEISSET;
224224
ompi_mpi_comm_null.comm.c_flags |= OMPI_COMM_INTRINSIC;
225225

ompi/datatype/ompi_datatype_create.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "opal/class/opal_pointer_array.h"
2727
#include "opal/util/printf.h"
28+
#include "opal/util/string_copy.h"
2829
#include "ompi/datatype/ompi_datatype.h"
2930
#include "ompi/attribute/attribute.h"
3031

@@ -113,7 +114,7 @@ ompi_datatype_duplicate( const ompi_datatype_t* oldType, ompi_datatype_t** newTy
113114

114115
char *new_name;
115116
opal_asprintf(&new_name, "Dup %s", oldType->name);
116-
strncpy(new_ompi_datatype->name, new_name, MPI_MAX_OBJECT_NAME - 1);
117+
opal_string_copy(new_ompi_datatype->name, new_name, MPI_MAX_OBJECT_NAME);
117118
new_ompi_datatype->name[MPI_MAX_OBJECT_NAME - 1] = '\0';
118119
free(new_name);
119120

ompi/datatype/ompi_datatype_module.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* University of Stuttgart. All rights reserved.
1111
* Copyright (c) 2004-2006 The Regents of the University of California.
1212
* All rights reserved.
13-
* Copyright (c) 2007-2012 Cisco Systems, Inc. All rights reserved.
13+
* Copyright (c) 2007-2018 Cisco Systems, Inc. All rights reserved
1414
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
1515
* Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
1616
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
@@ -32,6 +32,7 @@
3232

3333
#include "opal/datatype/opal_convertor_internal.h"
3434
#include "opal/util/output.h"
35+
#include "opal/util/string_copy.h"
3536
#include "opal/class/opal_pointer_array.h"
3637
#include "ompi/datatype/ompi_datatype.h"
3738
#include "ompi/datatype/ompi_datatype_internal.h"
@@ -420,7 +421,7 @@ opal_pointer_array_t ompi_datatype_f_to_c_table = {{0}};
420421
ptype->super.desc.desc = NULL; \
421422
ptype->super.opt_desc.desc = NULL; \
422423
OBJ_RELEASE( ptype ); \
423-
strncpy( (PDATA)->name, MPIDDTNAME, MPI_MAX_OBJECT_NAME ); \
424+
opal_string_copy( (PDATA)->name, MPIDDTNAME, MPI_MAX_OBJECT_NAME ); \
424425
} while(0)
425426

426427
#define DECLARE_MPI2_COMPOSED_BLOCK_DDT( PDATA, MPIDDT, MPIDDTNAME, MPIType, FLAGS ) \
@@ -438,14 +439,14 @@ opal_pointer_array_t ompi_datatype_f_to_c_table = {{0}};
438439
ptype->super.desc.desc = NULL; \
439440
ptype->super.opt_desc.desc = NULL; \
440441
OBJ_RELEASE( ptype ); \
441-
strncpy( (PDATA)->name, (MPIDDTNAME), MPI_MAX_OBJECT_NAME ); \
442+
opal_string_copy( (PDATA)->name, (MPIDDTNAME), MPI_MAX_OBJECT_NAME ); \
442443
} while(0)
443444

444445
#define DECLARE_MPI_SYNONYM_DDT( PDATA, MPIDDTNAME, PORIGDDT) \
445446
do { \
446447
/* just memcpy as it's easier this way */ \
447448
memcpy( (PDATA), (PORIGDDT), sizeof(ompi_datatype_t) ); \
448-
strncpy( (PDATA)->name, MPIDDTNAME, MPI_MAX_OBJECT_NAME ); \
449+
opal_string_copy( (PDATA)->name, MPIDDTNAME, MPI_MAX_OBJECT_NAME ); \
449450
/* forget the language flag */ \
450451
(PDATA)->super.flags &= ~OMPI_DATATYPE_FLAG_DATA_LANGUAGE; \
451452
(PDATA)->super.flags &= ~OPAL_DATATYPE_FLAG_PREDEFINED; \

0 commit comments

Comments
 (0)