github / github/codeql

LGTM.com - false positive: constant-comparison with assignment on one side

Open
#3,496 0 comments 0 reactions 0 assignees View on GitHub
C++ false-positive
Dominant language
CodeQL
Stars
10.1k
Forks
2.1k
Avg merge
2d 15h
Merged PRs (30d)
141

Description

I have

int next_char;
...
(next_char = gzgetc(file_)) != -1

where gzgetc is from zlib:

ZEXTERN int ZEXPORT gzgetc OF((gzFile file));

It triggers constant-comparison rule with message:

> Comparison is always true because ... = ... >= 0.

In this case (a = b) is integer assignment and can be negative.

https://lgtm.com/projects/g/project-gemmi/gemmi/snapshot/d1a210cf4810719b905806a690feade01e6eb5c9/files/include/gemmi/gz.hpp?sort=name&dir=ASC&mode=heatmap#x4ec8a4d86c53b859:1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.