Skip to content

Commit

Permalink
Prevent string out of bounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
DJDavies2 committed Jul 8, 2024
1 parent df7f157 commit 3b9d1f5
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/fckit/module/fckit_C_interop.F90
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,11 @@ function c_str_to_string(s) result(string)

subroutine copy_c_str_to_string(s,string)
use, intrinsic :: iso_c_binding
character(kind=c_char,len=1), intent(in) :: s(*)
character(kind=c_char,len=1), intent(in) :: s(:)
character(len=:), allocatable :: string
integer i, nchars
i = 1
do
do i = 1, size(s)
if (s(i) == c_null_char) exit
i = i + 1
enddo
nchars = i - 1 ! Exclude null character from Fortran string
FCKIT_ALLOCATE_CHARACTER(string,nchars)
Expand Down

0 comments on commit 3b9d1f5

Please sign in to comment.