fix(fortran): 修复 read_coord 中 line(0:0) 字符串越界导致崩溃

错误码 3221225785 (0xC0000005 = STATUS_ACCESS_VIOLATION) 由
read_coord 中列数统计的双重条件导致:
  line(i:i) /= ' ' .and. (i == 1 .or. line(i-1:i-1) == ' ')
Fortran 不保证 .or. 短路求值,当 i=1 时 line(0:0) 触发
内存越界。拆分为嵌套 if 块,确保只有在 i>1 时才访问
line(i-1:i-1)。
This commit is contained in:
2026-06-11 19:11:34 +08:00
parent b9ec622808
commit b783cbb981
2 changed files with 9 additions and 3 deletions
+7 -1
View File
@@ -334,7 +334,13 @@ subroutine read_coord(input_dir, n_atoms, atom_ids, masses, radii, pos_0, vel_0,
read(u, '(a)', iostat=ios) line
ncols = 0
do i = 1, len_trim(line)
if (line(i:i) /= ' ' .and. (i == 1 .or. line(i-1:i-1) == ' ')) ncols = ncols + 1
if (line(i:i) /= ' ') then
if (i == 1) then
ncols = ncols + 1
else if (line(i-1:i-1) == ' ') then
ncols = ncols + 1
end if
end if
end do
do