Skip to content

Commit 44e1673

Browse files
committed
add: length check guard before sign check
1 parent cbb255c commit 44e1673

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/strings/stdlib_str2num.fypp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ module stdlib_str2num
138138
!----------------------------------------------
139139
! Verify leading negative
140140
sign = 1
141-
if( iachar(s(p:p)) == minus_sign+digit_0 ) then
142-
sign = -1
143-
p = p + 1
141+
if(p<=len(s)) then
142+
if(iachar(s(p:p)) == minus_sign+digit_0 ) then
143+
sign = -1
144+
p = p + 1
145+
end if
144146
end if
145147
v = 0
146148
!----------------------------------------------

0 commit comments

Comments
 (0)