Skip to content

Commit c472c05

Browse files
committed
git-compat-util: suppress Coverity false positives from CONST_OUTPARAM
The CONST_OUTPARAM macro uses a dead ternary branch for compile-time type checking: (0 ? (*(out) = (in)), (out)) : (out)) The write *(out) = (in) never executes (guarded by "0 ?"), but it ensures that *out and in have compatible types. When skip_prefix(p, "literal", &p) expands, the third argument to skip_prefix_impl contains this dead write to p while the first argument reads p. Coverity's EVALUATION_ORDER checker does not eliminate the dead branch and flags this as an unsequenced read/write of the same variable, producing 122 false positives across the codebase. Model files cannot suppress this because the issue is in macro expansion, which happens before Coverity's function-level modeling. An earlier attempt to model skip_prefix_impl() in the Coverity model file had no effect because Coverity inlines the static inline function rather than using the model. Simplify CONST_OUTPARAM to just (out) under __COVERITY__, dropping the type-checking branch that confuses the checker. The type safety is preserved for real builds. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 6b70aed commit c472c05

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

git-compat-util.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,19 @@ void set_die_is_recursing_routine(int (*routine)(void));
499499
*
500500
* See the skip_prefix macro below for an example of use.
501501
*/
502+
/*
503+
* Coverity's EVALUATION_ORDER checker mistakes the dead ternary branch
504+
* for a live side effect: in skip_prefix(p, "x", &p) the expansion
505+
* contains *(out) = (in) in a 0-conditional, which Coverity reads as a
506+
* write to p while p is also read as the first argument. Simplify the
507+
* macro for Coverity to suppress 120+ false positives.
508+
*/
509+
#ifdef __COVERITY__
510+
#define CONST_OUTPARAM(in, out) (out)
511+
#else
502512
#define CONST_OUTPARAM(in, out) \
503513
((const char **)(0 ? ((*(out) = (in)),(out)) : (out)))
514+
#endif
504515

505516
/*
506517
* If the string "str" begins with the string found in "prefix", return true.

0 commit comments

Comments
 (0)