Invalid floating point exception with cJSON_CreateNumber(NAN)
还没有人认领这个 Issue。
评估
调研方向
从 cJSON_CreateNumber 入口点开始,重现提供的 FE_INVALID/NAN 示例。检查现有的数字转换行为,然后验证 NaN 处理能够避免异常,并在保留报告的 double 值的同时,为 valueint 提供一个有定义的值。
由索引模型根据 Issue 内容生成。
描述
Calling cJSON_CreateNumber(NAN) raises a FE_INVALID floating point exception.
Here is a sample code that shows the problem:
#define _GNU_SOURCE
#include "cJSON.h"
#include <fenv.h>
#include <math.h>
#include <stdio.h>
int main()
{
feenableexcept(FE_INVALID); // Crashes on FE_INVALID.
cJSON *n = cJSON_CreateNumber(NAN);
printf("n: %d %f\n", n->valueint, n->valuedouble);
cJSON_Delete(n);
}
While I guess this is technically not a bug, I think it would be nice if the library tested for NAN in cJSON_CreateNumber to avoid this, and also set the int value to a constant. Maybe something like:
item->type = cJSON_Number;
item->valuedouble = num;
if (isnan(num)) {
item->valueint = 0;
}
/* use saturation in case of overflow */
else if (num >= INT_MAX)
...
- 主要语言
- C
- 星标
- 13.1k
- 派生
- 3.6k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
DaveGamble/cJSON 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
DaveGamble/cJSON#1143 ·
-
[BUG] cJSON_PrintBuffered(item, 0, ...) with custom hooks: ensure() reads 1 byte from a zero-sized buffer (memcpy(..., p->offset + 1))可能已有人在做 @ck0i 于 19 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
DaveGamble/cJSON#1122 · 1 条评论 ·
-
pointer comparsion undefined behavior in cJSON_SetValuestring可能已有人在做 @kanishk25249-sudo 于 18 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
DaveGamble/cJSON#1106 ·
-
Undefined-Behavior in function cJSON_SetNumberHelper可能已有人在做 @akashdeshmukh-git 于 25 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
DaveGamble/cJSON#1100 · 1 个 reaction ·
-
CMake config files contain absolute install paths可能已有人在做 @akashdeshmukh-git 于 36 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
DaveGamble/cJSON#1094 · 9 条评论 · 1 个 reaction ·
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 2 天内回复
-
难度 1/5 1 小时以内 新手友好度 62/100
libsndfile/libsndfile#1238 ·
-
难度 1/5 1 小时以内 新手友好度 88/100
quickjs-ng/quickjs#1959 ·
维护者通常 1 天内回复
-
Claude:Bug GPT:Bug triage
难度 2/5 1-3 小时 新手友好度 65/100
open5gs/open5gs#5161 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复