github / github/codeql

False positive "Comparison result is always the same" because of incorrect sizeof evaluation

未关闭
#17,343 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
false-positive
主要语言
CodeQL
星标
10.1k
派生
2.1k
平均合并
2 天 15 小时
30 天内合并 PR
141

描述

**Description of the false positive**

CodeQL complains "Comparison is always true because i <= 1. "

However, it is really a loop over 4 elements.

I suspect the problem is that
```c
struct foo
{
...
unsigned long (*fnptr_array[4])(void);
...
};
```
describes an array of 4 function pointers, but that CodeQL isn't evaluating `sizeof` correctly on the type.

**Code samples or links to source code**

https://github.com/andyhhp/xtf/blob/f503efe8e5cf8858ec0704f1aaa82d0bf50891a5/tests/swint-emulation/main.c#L162-L162

but I've done a simpler example in https://godbolt.org/z/9fGr51r68 if that helps

**URL to the alert on GitHub code scanning (optional)**

https://github.com/andyhhp/xtf/security/code-scanning/55

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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