From a980ee5ca126f8df0376f37ddfc57dedb8e77f6a Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Tue, 30 Oct 2012 17:56:28 +0000 Subject: [PATCH] Update to r27292: only use "valuelen-1" when the valuelen is MPI_MAX_INFO_VAL (so that we don't go beyond the end of the string). But otherwise, abibe by what says in MPI-2.2 / MPI-3.0 in the description of MPI_INFO_GET (where "it" refers to the valuelen argument): If it is less than the actual size of the value, the value is truncated. In C, valuelen should be one less than the amount of allocated space to allow for the null terminator. cmr:v1.7 This commit was SVN r27522. The following SVN revision numbers were found above: r27292 --> open-mpi/ompi@fb4af5e29c2f03746dbdefc5e773f15437d8ca21 --- ompi/info/info.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ompi/info/info.c b/ompi/info/info.c index 4d67c318b0..e916322af8 100644 --- a/ompi/info/info.c +++ b/ompi/info/info.c @@ -314,7 +314,11 @@ int ompi_info_get (ompi_info_t *info, char *key, int valuelen, strcpy(value, search->ie_value); } else { opal_strncpy(value, search->ie_value, valuelen); - value[valuelen-1] = 0; + if (MPI_MAX_INFO_VAL == valuelen) { + value[valuelen-1] = 0; + } else { + value[valuelen] = 0; + } } } OPAL_THREAD_UNLOCK(info->i_lock);