@@ -31,7 +31,8 @@ subroutine collect_logspace(testsuite)
3131 new_unittest(" logspace_default" , test_logspace_default), &
3232 new_unittest(" logspace_base_2" , test_logspace_base_2), &
3333 new_unittest(" logspace_base_2_cmplx_start" , test_logspace_base_2_cmplx_start), &
34- new_unittest(" logspace_base_i_int_start" , test_logspace_base_i_int_start) &
34+ new_unittest(" logspace_base_i_int_start" , test_logspace_base_i_int_start), &
35+ new_unittest(" logspace_int_overflow" , test_logspace_int_overflow) &
3536 ]
3637
3738 end subroutine collect_logspace
@@ -242,6 +243,43 @@ subroutine test_logspace_base_i_int_start(error)
242243
243244 end subroutine
244245
246+ ! Regression test for issue #1055: integer start/end caused overflow in
247+ ! intermediate integer arithmetic, producing garbage results.
248+ subroutine test_logspace_int_overflow (error )
249+ ! > Error handling
250+ type (error_type), allocatable , intent (out ) :: error
251+
252+ integer , parameter :: n = 3
253+ integer , parameter :: start = 10
254+ integer , parameter :: end = 23
255+ real (dp) :: expected_proportion
256+ integer :: i
257+
258+ real (dp), allocatable :: x(:)
259+
260+ x = logspace(start, end, n)
261+
262+ expected_proportion = 10.0_dp ** ( real (end - start, dp) / real (n - 1 , dp) )
263+
264+ call check(error, size (x), n, " Array not allocated to appropriate size" )
265+ if (allocated (error)) return
266+ call check(error, x(1 ), 10.0_dp ** start, &
267+ & " Initial value not equal to 10^start (possible integer overflow)" , &
268+ & thr= abs (10.0_dp ** start) * TOLERANCE_DP)
269+ if (allocated (error)) return
270+ call check(error, x(n), 10.0_dp ** end, &
271+ & " Final value not equal to 10^end (possible integer overflow)" , &
272+ & thr= abs (10.0_dp ** end) * TOLERANCE_DP)
273+ if (allocated (error)) return
274+
275+ do i = 1 , n-1
276+ call check(error, x(i + 1 ) / x(i), expected_proportion, &
277+ & thr= abs (expected_proportion) * TOLERANCE_DP)
278+ if (allocated (error)) return
279+ end do
280+
281+ end subroutine
282+
245283
246284end module
247285
0 commit comments