Avoid an out-of-bounds read in the uniq example
Apparently, the Fortran standard does not enforce the short-circuit evaluation. Although gfortran
performs it at the optimization levels -O1
and higher, the runtime out-of-bounds check, generated with the -fbounds-check
compiler flag, works as if there were no short-circuiting. Therefore, IF (k == 1 .OR. ... OutputArray(k - 1) ...
results in Fortran runtime error: Index '0' of dimension 1 of array 'outputarray' below lower bound of 1
when k == 1
.
This MR makes the code (in a rather awkward way) independent of the short-circuit optimizations to avoid possible out-of-bounds memory access. Additionally, CI jobs that test with gfortran
now build with the -fbounds-check
Fortran compiler flag.