Skip to content

[flang][runtime] Better handling for integer input into null address #135987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2025
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
19 changes: 11 additions & 8 deletions flang-rt/lib/runtime/edit-input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ static RT_API_ATTRS char ScanNumericPrefix(IoStatementState &io,

RT_API_ATTRS bool EditIntegerInput(IoStatementState &io, const DataEdit &edit,
void *n, int kind, bool isSigned) {
RUNTIME_CHECK(io.GetIoErrorHandler(), kind >= 1 && !(kind & (kind - 1)));
auto &handler{io.GetIoErrorHandler()};
RUNTIME_CHECK(handler, kind >= 1 && !(kind & (kind - 1)));
if (!n) {
handler.Crash("Null address for integer input item");
}
switch (edit.descriptor) {
case DataEdit::ListDirected:
if (IsNamelistNameOrSlash(io)) {
Expand All @@ -207,7 +211,7 @@ RT_API_ATTRS bool EditIntegerInput(IoStatementState &io, const DataEdit &edit,
case 'A': // legacy extension
return EditCharacterInput(io, edit, reinterpret_cast<char *>(n), kind);
default:
io.GetIoErrorHandler().SignalError(IostatErrorInFormat,
handler.SignalError(IostatErrorInFormat,
"Data edit descriptor '%c' may not be used with an INTEGER data item",
edit.descriptor);
return false;
Expand All @@ -217,7 +221,7 @@ RT_API_ATTRS bool EditIntegerInput(IoStatementState &io, const DataEdit &edit,
auto fastField{io.GetUpcomingFastAsciiField()};
char sign{ScanNumericPrefix(io, edit, next, remaining, &fastField)};
if (sign == '-' && !isSigned) {
io.GetIoErrorHandler().SignalError("Negative sign in UNSIGNED input field");
handler.SignalError("Negative sign in UNSIGNED input field");
return false;
}
common::uint128_t value{0};
Expand Down Expand Up @@ -254,8 +258,7 @@ RT_API_ATTRS bool EditIntegerInput(IoStatementState &io, const DataEdit &edit,
break;
}
}
io.GetIoErrorHandler().SignalError(
"Bad character '%lc' in INTEGER input field", ch);
handler.SignalError("Bad character '%lc' in INTEGER input field", ch);
return false;
}
static constexpr auto maxu128OverTen{maxu128 / 10};
Expand All @@ -268,7 +271,7 @@ RT_API_ATTRS bool EditIntegerInput(IoStatementState &io, const DataEdit &edit,
any = true;
}
if (!any && !remaining) {
io.GetIoErrorHandler().SignalError(
handler.SignalError(
"Integer value absent from NAMELIST or list-directed input");
return false;
}
Expand All @@ -280,14 +283,14 @@ RT_API_ATTRS bool EditIntegerInput(IoStatementState &io, const DataEdit &edit,
overflow |= value >= maxForKind;
}
if (overflow) {
io.GetIoErrorHandler().SignalError(IostatIntegerInputOverflow,
handler.SignalError(IostatIntegerInputOverflow,
"Decimal input overflows INTEGER(%d) variable", kind);
return false;
}
if (sign == '-') {
value = -value;
}
if (any || !io.GetIoErrorHandler().InError()) {
if (any || !handler.InError()) {
// The value is stored in the lower order bits on big endian platform.
// For memcpy, shift the value to the highest order bits.
#if USING_NATIVE_INT128_T
Expand Down
Loading