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
+2 -2
View File
@@ -16,7 +16,7 @@ plot_wave_save_mp4: 1 # 输出波形 MP4(需 step_plot_wave=1
# ── 计算引擎 ──────────────────────────────────
# 可选: python, c, cpp, fortran, java
engine: python # 默认使用 python 引擎
engine: fortran # 默认使用 python 引擎
# ── 盒子 ──────────────────────────────────────
box_a: 80.0 # 立方体半边长,粒子被限制在 [-box_a, box_a]³ 内
@@ -63,7 +63,7 @@ warmup_steps: 0 # 默认 0(立即开始记录)
# 总模拟时间(秒),程序自动计算 NT = T_total / DT
# 如果同时指定了 NT,以 NT 为准
T_total: 4.0
T_total: 10.0
# 抽帧间隔(每 NSTEP 步取一帧用于动画)
NSTEP: 100