[flang-commits] [flang] 15e4a3c - [flang][runtime] Fix namelist substring checking (#78649)

via flang-commits flang-commits at lists.llvm.org
Thu Jan 25 15:15:25 PST 2024


Author: Peter Klausler
Date: 2024-01-25T15:15:20-08:00
New Revision: 15e4a3c1fb12f09d4f87b9e8bf68cb31de3d0944

URL: https://github.com/llvm/llvm-project/commit/15e4a3c1fb12f09d4f87b9e8bf68cb31de3d0944
DIFF: https://github.com/llvm/llvm-project/commit/15e4a3c1fb12f09d4f87b9e8bf68cb31de3d0944.diff

LOG: [flang][runtime] Fix namelist substring checking (#78649)

An || operator in namelist substring bounds checking really needs to be
an && operator so that the substring is viewed as correct only when both
its bounds are valid.

Fixes llvm-test-suite/Fortran/gfortran/regression/namelist_40.f90.

Added: 
    

Modified: 
    flang/runtime/namelist.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp
index 848ebcf300a3d9e..f5d7404fdcb86b7 100644
--- a/flang/runtime/namelist.cpp
+++ b/flang/runtime/namelist.cpp
@@ -313,7 +313,7 @@ static bool HandleSubstring(
         desc.raw().elem_len = 0;
         return true;
       }
-      if (*lower >= 1 || *upper <= chars) {
+      if (*lower >= 1 && *upper <= chars) {
         // Offset the base address & adjust the element byte length
         desc.raw().elem_len = (*upper - *lower + 1) * kind;
         desc.set_base_addr(reinterpret_cast<void *>(


        


More information about the flang-commits mailing list