Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions ompi/mpi/fortran/base/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Copyright (c) 2010-2018 Cisco Systems, Inc. All rights reserved
* Copyright (c) 2017 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2025 Jeffrey M. Squyres. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -95,8 +96,19 @@ int ompi_fortran_string_c2f(const char *cstr, char *fstr, int len)
int i;

opal_string_copy(fstr, cstr, len);
for (i = strlen(cstr); i < len; ++i) {
fstr[i] = ' ';

// If len < len(cstr), then opal_string_copy() will have copied a
// trailing \0 into the last position in fstr. This is not what
// Fortran wants; overwrite that \0 with the actual last character
// that will fit into fstr.
if (len <= strlen(cstr)) {
fstr[len - 1] = cstr[len - 1];
} else {
// Otherwise, pad the end of the resulting Fortran string with
// spaces.
for (i = strlen(cstr); i < len; ++i) {
fstr[i] = ' ';
}
}

return OMPI_SUCCESS;
Expand Down
Loading