[flang-commits] [flang] [flang][runtime] Fix use of empty optional in BOZ input (PR #120789)

via flang-commits flang-commits at lists.llvm.org
Fri Dec 20 11:30:49 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

Slava reported a valgrind result showing the use of uninitialized data due to an unconditional dereference of an optional in BOZ formatted input editing; fix.

---
Full diff: https://github.com/llvm/llvm-project/pull/120789.diff


1 Files Affected:

- (modified) flang/runtime/edit-input.cpp (+1-1) 


``````````diff
diff --git a/flang/runtime/edit-input.cpp b/flang/runtime/edit-input.cpp
index c714a85a336e72..317f0b676bd21b 100644
--- a/flang/runtime/edit-input.cpp
+++ b/flang/runtime/edit-input.cpp
@@ -130,7 +130,7 @@ static RT_API_ATTRS bool EditBOZInput(
     shift = shift - 8; // misaligned octal
   }
   while (digits > 0) {
-    char32_t ch{*io.NextInField(remaining, edit)};
+    char32_t ch{io.NextInField(remaining, edit).value_or(' ')};
     int digit{0};
     if (ch == ' ' || ch == '\t') {
       if (edit.modes.editingFlags & blankZero) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/120789


More information about the flang-commits mailing list