diff --git a/flang/runtime/assign.cpp b/flang/runtime/assign.cpp index 095c4d3b9eefd..0b64020811bca 100644 --- a/flang/runtime/assign.cpp +++ b/flang/runtime/assign.cpp @@ -223,12 +223,13 @@ static void BlankPadCharacterAssignment(Descriptor &to, const Descriptor &from, SubscriptValue toAt[], SubscriptValue fromAt[], std::size_t elements, std::size_t toElementBytes, std::size_t fromElementBytes) { std::size_t padding{(toElementBytes - fromElementBytes) / sizeof(CHAR)}; + std::size_t copiedCharacters{fromElementBytes / sizeof(CHAR)}; for (; elements-- > 0; to.IncrementSubscripts(toAt), from.IncrementSubscripts(fromAt)) { CHAR *p{to.Element(toAt)}; std::memmove( p, from.Element>(fromAt), fromElementBytes); - p += fromElementBytes; + p += copiedCharacters; for (auto n{padding}; n-- > 0;) { *p++ = CHAR{' '}; }