Menu

#28 False positive on "mismatch" enumeration

v1.0 (example)
closed
nobody
None
5
1 day ago
2025-06-06
Flash
No

I have an enumeration that has a value mismatch. Every reference to this value yields an obtuse warning:

[1] (buffer) mismatch:Function does not check the second iterator for over-read conditions (CWE-126). This functino is often discouraged by most C++ coding standards in favor of its safer alternatives provided since C++14. Consider using a form of this function that checks the second iterator before potentially overflowing it.

I'm guessing the warning is related to std::mismatch() but the whole point of namespace scoping is to disambiguate commonly used names.

class Foo {
public:
    enum MatchState {
        invalid,
        ignored,
        exact_match,
        near_match,
        mismatch,
        match_new,
        mismatch_new,
    };
};

Discussion

  • David A. Wheeler

    The false positive occurs because flawfinder is a lexical scanner. It matches function names by text, without parsing the code structure. When it sees mismatch it cannot tell whether it is a call to std::mismatch() or a reference to an enum member with the same name.

    However, there is a useful distinction available without an AST: a function call is always followed by (, but an enum member reference never is. I plan to fix this by checking whether a ( was found after the matched name before issuing the warning. If no ( is present, the name would be treated as an identifier (enum member, variable, etc.) rather than a function call, and no warning would be issued. Actual calls to std::mismatch(), std::equal(), and std::is_permutation() would continue to be flagged as before.

    I plan to include this fix in the next release.

     
  • David A. Wheeler

    Fixed in master (main branch), will be in next release.

     
  • David A. Wheeler

    • status: open --> closed
     
  • David A. Wheeler

    Fixed in master (main branch), will be in next release.

     

Log in to post a comment.

MongoDB Logo MongoDB