Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

UB: (int) cast of a user double outside int range in dispatch / vm_index_is_int / flat_index_at

未关闭 适合新手
#1,748 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c
领域
compilers

调研方向

从指定的四个位置开始:src/builtins.c 约第 5946 行的 builtin_dispatch、src/vm.c 中的 vm_index_is_int、src/builtins_tensor.c 中 flat_index_at 的列表分支,以及 finite_num_to_byte。在 make asan 下使用 issue 中的分发代码片段复现,查看 UBSan 的 float-cast-overflow 报告。完成标准为:每个位置在强制转换前对 double 做范围检查(NaN 判为假);grep -n '(int)' src/*.c 的结果已完成分类;复现程序输出 value 错误,且不再出现任何 runtime error: 行。

由索引模型根据 Issue 内容生成。

描述

area:runtime-vm kind:silent-wrong

Found while building #1746 Phase 1. Several sites convert a user double to int with a bare (int) cast before any range check. For |x| >= 2^31 (today: up to ±1e308; under an IEEE build also inf/NaN) that is undefined behaviour, and UBSan's float-cast-overflow (on in every ASan variant) reports it.

Repro (any asan build):

define g(x) as:
    return x
d is dispatch
print of (d of [[g], 1e308, 5])

-> src/builtins.c:5946:20: runtime error: 1e+308 is outside the range of representable values of type 'int' (then the intended dispatch key must be an integer raise).

Sites: builtin_dispatch (builtins.c, (int)eigs_num_arg(key_v, ...)), vm_index_is_int (vm.c), flat_index_at list arm (builtins_tensor.c), finite_num_to_byte ((int)fmod(x,256) with a NaN). The #1746 experiment guards only vm_index_is_int, only under -DEIGS_IEEE.

Done when

  • Each listed site range-checks (!(d >= INT_MIN && d <= INT_MAX) style, NaN-false) before the cast, and the sweep grep -n '(int)' src/*.c over user-double conversions is classified.
  • The repro above is clean under make asan (no runtime error:), and still raises value.
主要语言
C
星标
3
派生
7
平均合并
11 小时 45 分钟
30 天内合并 PR
273

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

InauguralSystems/EigenScript 的其他 Issue

查看 InauguralSystems/EigenScript 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。