Skip to content

Commit 5ad2837

Browse files
authored
Merge pull request #655 from degawa/feature/issue_647
fixed 32-bit integer overflow in stdlib_io_npy
2 parents d654b26 + c4701c5 commit 5ad2837

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/stdlib_io_npy_load.fypp

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ contains
134134

135135
if (major > 1) then
136136
header_len = ichar(buf(1)) &
137-
& + ichar(buf(2)) * 2**8 &
138-
& + ichar(buf(3)) * 2**16 &
139-
& + ichar(buf(4)) * 2**32
137+
& + ichar(buf(2)) * 256**1 &
138+
& + ichar(buf(3)) * 256**2 &
139+
& + ichar(buf(4)) * 256**3
140140
else
141141
header_len = ichar(buf(1)) &
142-
& + ichar(buf(2)) * 2**8
142+
& + ichar(buf(2)) * 256**1
143143
end if
144144
allocate(character(header_len) :: dict, stat=stat)
145145
if (stat /= 0) return

src/stdlib_io_npy_save.fypp

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ contains
6060
!> String of bytes
6161
character(len=4) :: str
6262

63-
str = achar(mod(val, 2**8)) // &
64-
& achar(mod(val, 2**16) / 2**8) // &
65-
& achar(mod(val, 2**32) / 2**16) // &
66-
& achar(val / 2**32)
63+
str = achar(mod(val, 256**1)) // &
64+
& achar(mod(val, 256**2) / 256**1) // &
65+
& achar(mod(val, 256**3) / 256**2) // &
66+
& achar(val / 256**3)
6767
end function to_bytes_i4
6868

6969

0 commit comments

Comments
 (0)