From 905bf8529539ab5d01cf3796739c8fdf72a39e42 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Mon, 23 May 2005 21:45:20 +0000 Subject: [PATCH] Be more careful with datatype names. This commit was SVN r5833. --- src/mpi/c/type_get_name.c | 7 +++++-- src/mpi/c/type_set_name.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mpi/c/type_get_name.c b/src/mpi/c/type_get_name.c index f9eb176893..0761005386 100644 --- a/src/mpi/c/type_get_name.c +++ b/src/mpi/c/type_get_name.c @@ -48,9 +48,12 @@ int MPI_Type_get_name(MPI_Datatype type, char *type_name, int *resultlen) } } - /* Simple */ + /* Simple. Copy over the entire name (including all blanks at the + end) because a) the user must have passed us a string of at + least length MPI_MAX_OBJECT_LEN, and b) if this is a call from + Fortran, the string may require null padding on the right. */ *resultlen = strlen(type->name); - strncpy( type_name, type->name, *resultlen ); + strncpy(type_name, type->name, MPI_MAX_OBJECT_NAME); return MPI_SUCCESS; } diff --git a/src/mpi/c/type_set_name.c b/src/mpi/c/type_set_name.c index b365644e00..394528d151 100644 --- a/src/mpi/c/type_set_name.c +++ b/src/mpi/c/type_set_name.c @@ -48,11 +48,11 @@ int MPI_Type_set_name (MPI_Datatype type, char *type_name) } } + memset(type->name, 0, MPI_MAX_OBJECT_NAME); length = strlen( type_name ); if( length >= MPI_MAX_OBJECT_NAME ) { length = MPI_MAX_OBJECT_NAME - 1; } strncpy( type->name, type_name, length ); - type->name[length + 1] = '\0'; return MPI_SUCCESS; }