Silverfrost Forums

Welcome to our forums

INTEGER overflow detection

5 Oct 2006 4:20 #1118

Hi Paul!

Here is another problem with the detection of INTEGER overflows. I have tested v4.91 and proofed that the program did not catch the overflow. CVF 6.6 and IVF 9.0 don't detect it too.

Kind regards,

Joerg QT software

Winapp Program Test_OutofRange

Implicit None

Integer , Parameter :: iKind = selected_int_kind (2)

Integer (iKind) :: k

write (,) ' Results of Program Test_OutofRange' write (,) ' ==================================' write (,)

write (,) ' Kind of k = ', iKind write (,) ' Huge (k) = ', Huge (k) write (,) write (,) ' Kind of 9999 = ', kind (9999) write (,) ' Huge of 9999 = ', Huge (9999) write (,) write (,)

! Clearly, k = 9999 is out of range, i.e. gt 127. ! A program stop should occur. ! Instead a wrong value (k=15) is given for the variable k; please see the output.

k = 9999

! k = 9999_iKind gives an error message during compilation

write (,) 'The assignment statement k = 9999 gives k = ', k write (,) 'without any warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'

End Program Test_OutofRange

5 Oct 2006 4:22 #1119

Here is another program of that customer showing the INTEGER overflow occuring without any message of the compiler runtime system (CVF and IVF fail too).

Kind regards,

Joerg

Program Test_overflow

Implicit None

! For iKind = selected_int_kind (9) overflow works correctly ! ###########################################################

Integer , Parameter :: iKind = selected_int_kind (4)

Integer (iKind) :: i, k

write (,) ' Results of Program Test_overflow' write (,) ' ================================' write (,)

write (,) ' iKind = ', iKind write (,) ' Huge (i) = ', Huge (i) write (,)

! For the Do Loop index i = 5, an error message should be given and ! a program stop should occur; ! instead wrong values are given for the variable k; please see output.

 k = 10_iKind

Do i = 1, 10 write (,) ' Do-Loop index i = ', i, ' Value of k = ', k k = k * 10_iKind End Do

write (,) write (,) ' The results for Do Loop index = 5,6,...,10 are completely wrong!' write (,) ' ################################################################'

End Program Test_overflow

6 Oct 2006 4:14 #1121

Joerg

The documentation says that integer overflow is only trapped when CHECKMATE is switched on.

Regards

Paul

6 Oct 2006 1:17 #1128

I have tested several configurations in Plato 3. Among these CHECKMATE-Win32. I have also tried different combination of compiler switches. But none lead to a program abort when an overflow occurs. Which options should I use? Thank you, Paul. Joerg

19 Oct 2006 1:25 #1157

Joerg

At the moment it appears that integer overflow is not trapped on simple assignment such as k = 9999 nor k= 99*99 which is probably resolved by the compiler. This does not seem unreasonable since the programmer should be aware of this.

But it is trapped in arithmetic expressions such as

k = 99 k = k*k

We will run a few tests to see if this can be improved.

19 Oct 2006 10:26 #1160

Joerg

The response to integer overflow has now been improved under Win32. This will be included in the next release (version 5.0).

Regards

Paul

Please login to reply.