Skip to content
Snippets Groups Projects
Commit 0260a8af authored by Sergey Kosukhin's avatar Sergey Kosukhin
Browse files

Avoid an out-of-bounds read in the uniq example

parent 253ff439
No related branches found
No related tags found
1 merge request!77Avoid an out-of-bounds read in the uniq example
......@@ -201,22 +201,40 @@ CONTAINS
j = 1
k = 1
! Handle the first element (we cannot put this into the loop below because
! the compiler might not perform the short-circuit evaluation):
IF (i <= na .AND. j <= nb) THEN
diff = 86400000_i8*(InputArray1(i)%day - InputArray2(j)%day) + InputArray1(i)%ms - InputArray2(j)%ms
IF (diff < 0_i8) THEN
OutputArray(k) = InputArray1(i)
i = i + 1
ELSE IF (diff > 0_i8) THEN
OutputArray(k) = InputArray2(j)
j = j + 1
ELSE
OutputArray(k) = InputArray1(i)
i = i + 1
j = j + 1
END IF
k = k + 1
END IF
DO WHILE (i <= na .AND. j <= nb)
diff = 86400000_i8*(InputArray1(i)%day - InputArray2(j)%day) + InputArray1(i)%ms - InputArray2(j)%ms
IF (diff < 0_i8) THEN
IF (k == 1 .OR. ((InputArray1(i)%day /= OutputArray(k - 1)%day) .OR. (InputArray1(i)%ms /= OutputArray(k - 1)%ms))) THEN
IF ((InputArray1(i)%day /= OutputArray(k - 1)%day) .OR. (InputArray1(i)%ms /= OutputArray(k - 1)%ms)) THEN
OutputArray(k) = InputArray1(i)
k = k + 1
END IF
i = i + 1
ELSE IF (diff > 0_i8) THEN
IF (k == 1 .OR. ((InputArray2(j)%day /= OutputArray(k - 1)%day) .OR. (InputArray2(j)%ms /= OutputArray(k - 1)%ms))) THEN
IF ((InputArray2(j)%day /= OutputArray(k - 1)%day) .OR. (InputArray2(j)%ms /= OutputArray(k - 1)%ms)) THEN
OutputArray(k) = InputArray2(j)
k = k + 1
END IF
j = j + 1
ELSE
IF (k == 1 .OR. ((InputArray1(i)%day /= OutputArray(k - 1)%day) .OR. (InputArray1(i)%ms /= OutputArray(k - 1)%ms))) THEN
IF ((InputArray1(i)%day /= OutputArray(k - 1)%day) .OR. (InputArray1(i)%ms /= OutputArray(k - 1)%ms)) THEN
OutputArray(k) = InputArray1(i)
k = k + 1
END IF
......@@ -245,9 +263,9 @@ CONTAINS
END IF
END DO
! do i = 1, k-1
! write (0,*) OutputArray(i)
! enddo
! DO i = 1, k - 1
! WRITE (0, *) OutputArray(i)
! END DO
nsize_OA = k - 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment