Skip to content

ist: suppress Coverity false INTEGER_OVERFLOW via __COVERITY__ guard#32

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/coverity-modeling-suppress-issue
Draft

ist: suppress Coverity false INTEGER_OVERFLOW via __COVERITY__ guard#32
Copilot wants to merge 2 commits intomasterfrom
copilot/coverity-modeling-suppress-issue

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 1, 2026

Coverity (CID 1646569) flags the ist() macro as INTEGER_OVERFLOW because it uses an intentional size_t underflow trick to measure string length inline without calling strlen():

size_t __l = 0;
if (__x) for (__l--; __x[++__l]; ) ;  /* __l-- wraps 0→SIZE_MAX intentionally */

Coverity sees __l-- from 0 as underflow and ++__l from SIZE_MAX as overflow, and cannot determine the pattern is safe.

Changes

  • include/import/ist.h: Restructure ist() macro guards to #ifdef __COVERITY__ / #elif __GNUC__ >= 4 / #else. The Coverity branch uses a plain strlen()-based implementation (no underflow trick), which Coverity understands cleanly. Normal builds are unaffected.

Coverity defines __COVERITY__ automatically during analysis, so no workflow changes are required.

Copilot AI linked an issue Apr 1, 2026 that may be closed by this pull request
The ist() macro uses an intentional size_t underflow trick for efficient
runtime string length measurement:

    size_t __l = 0;
    if (__x) for (__l--; __x[++__l]; ) ;

Coverity reports this as INTEGER_OVERFLOW (CID 1646569) because __l--
underflows from 0 to SIZE_MAX, and ++__l overflows from SIZE_MAX back to 0.

Add a #ifdef __COVERITY__ guard that provides a straightforward strlen()-
based implementation when Coverity runs its analysis. Coverity defines
__COVERITY__ automatically during scans, so no workflow changes are needed.

Agent-Logs-Url: https://github.com/chipitsine/haproxy/sessions/5eb4610f-492c-4202-a2b6-8ed07062a798

Co-authored-by: chipitsine <2217296+chipitsine@users.noreply.github.com>
Copilot AI changed the title [WIP] Add coverity modeling to suppress integer overflow findings ist: suppress Coverity false INTEGER_OVERFLOW via __COVERITY__ guard Apr 1, 2026
Copilot AI requested a review from chipitsine April 1, 2026 06:58
@chipitsine
Copy link
Copy Markdown
Owner

can we use modelling instead of guard?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

coverity modeling

2 participants