diff --git a/ompi/mpi/f77/error_string_f.c b/ompi/mpi/f77/error_string_f.c index a180e84755..bbc739c657 100644 --- a/ompi/mpi/f77/error_string_f.c +++ b/ompi/mpi/f77/error_string_f.c @@ -82,8 +82,6 @@ void mpi_error_string_f(MPI_Fint *errorcode, char *string, )); if (MPI_SUCCESS == OMPI_FINT_2_INT(*ierr)) { OMPI_SINGLE_INT_2_FINT(resultlen); - string_len = (string_len < MPI_MAX_ERROR_STRING) ? - string_len : MPI_MAX_ERROR_STRING; if (OMPI_SUCCESS != (ret = ompi_fortran_string_c2f(c_string, string, string_len))) { c_err = OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, ret, FUNC_NAME); diff --git a/ompi/mpi/f77/file_get_view_f.c b/ompi/mpi/f77/file_get_view_f.c index 2f69a36f74..32931e1eef 100644 --- a/ompi/mpi/f77/file_get_view_f.c +++ b/ompi/mpi/f77/file_get_view_f.c @@ -74,6 +74,6 @@ void mpi_file_get_view_f(MPI_Fint *fh, MPI_Offset *disp, *disp = (MPI_Fint) c_disp; *etype = MPI_Type_c2f(c_etype); *filetype = MPI_Type_c2f(c_filetype); - ompi_fortran_string_c2f(c_datarep, datarep, MPI_MAX_DATAREP_STRING); + ompi_fortran_string_c2f(c_datarep, datarep, datarep_len); } } diff --git a/ompi/mpi/f77/get_processor_name_f.c b/ompi/mpi/f77/get_processor_name_f.c index 5972829f5c..b6ef576b15 100644 --- a/ompi/mpi/f77/get_processor_name_f.c +++ b/ompi/mpi/f77/get_processor_name_f.c @@ -80,8 +80,8 @@ void mpi_get_processor_name_f(char *name, MPI_Fint *resultlen, MPI_Fint *ierr, if (MPI_SUCCESS == OMPI_FINT_2_INT(*ierr)) { OMPI_SINGLE_INT_2_FINT(resultlen); - name_len = (name_len < OMPI_FINT_2_INT(*resultlen)) ? - name_len : OMPI_FINT_2_INT(*resultlen); + /* Use the full length of the Fortran string, not *resultlen. + See comment in ompi/mpi/f77/strings.c. */ if (OMPI_SUCCESS != (ret = ompi_fortran_string_c2f(c_name, name, name_len))) { c_err = OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, ret, FUNC_NAME); diff --git a/ompi/mpi/f77/info_get_f.c b/ompi/mpi/f77/info_get_f.c index 958cacd889..68f4d9efed 100644 --- a/ompi/mpi/f77/info_get_f.c +++ b/ompi/mpi/f77/info_get_f.c @@ -91,8 +91,8 @@ void mpi_info_get_f(MPI_Fint *info, char *key, MPI_Fint *valuelen, if (MPI_SUCCESS == OMPI_FINT_2_INT(*ierr)) { OMPI_SINGLE_INT_2_LOGICAL(flag); - value_len = (value_len < OMPI_FINT_2_INT(*valuelen)) ? - value_len : OMPI_FINT_2_INT(*valuelen); + /* Use the full length of the Fortran string, not *valuelen. + See comment in ompi/mpi/f77/strings.c. */ if (OMPI_SUCCESS != (ret = ompi_fortran_string_c2f(c_value, value, value_len))) { c_err = OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, ret, FUNC_NAME); diff --git a/ompi/mpi/f77/info_get_nthkey_f.c b/ompi/mpi/f77/info_get_nthkey_f.c index 4d2b933e36..5cb85aa800 100644 --- a/ompi/mpi/f77/info_get_nthkey_f.c +++ b/ompi/mpi/f77/info_get_nthkey_f.c @@ -81,7 +81,6 @@ void mpi_info_get_nthkey_f(MPI_Fint *info, MPI_Fint *n, char *key, OMPI_FINT_2_INT(*n), c_key)); - key_len = (key_len < MPI_MAX_INFO_KEY) ? key_len : MPI_MAX_INFO_KEY; if (OMPI_SUCCESS != (ret = ompi_fortran_string_c2f(c_key, key, key_len))) { c_err = OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, ret, FUNC_NAME); *ierr = OMPI_INT_2_FINT(c_err); diff --git a/ompi/mpi/f77/strings.c b/ompi/mpi/f77/strings.c index 357662a5d7..7dd36c36ec 100644 --- a/ompi/mpi/f77/strings.c +++ b/ompi/mpi/f77/strings.c @@ -71,7 +71,18 @@ int ompi_fortran_string_f2c(char *fstr, int len, char **cstr) /* - * copy a C string into a Fortran string + * Copy a C string into a Fortran string. Note that when Fortran + * copies strings, even if it operates on subsets of the strings, it + * is expected to zero out the rest of the string with spaces. Hence, + * when calling this function, the "len" parameter should be the + * compiler-passed length of the entire string, even if you're copying + * over less than the full string. Specifically: + * + * http://www.ibiblio.org/pub/languages/fortran/ch2-13.html + * + * "Whole operations 'using' only 'part' of it, e.g. assignment of a + * shorter string, or reading a shorter record, automatically pads the + * rest of the string with blanks." */ int ompi_fortran_string_c2f(char *cstr, char *fstr, int len) {