Hi all,
I'm interested in enabling the following clang-tidy checks:
bugprone-redundant-branch-condition
This diagnostic finds condition variables in nested `if` statements that were *also* checked in an outer `if` statement and have not changed.
Such checks are at minimum redundant and may indicate some logic failure to the developer (why are they thinking a particular condition needs to be checked multiple times?).
It triggers 16 times in Chromium's codebase, in a variety of third_party libraries (angle, blink, swiftshader, icu), as well as chrome/renderer.
Auditing the sites, I found no false positives and it seemed like the code would be clearer and more self-evidently correct in every case if the redundant branch were removed (
example,
example,
example).
bugprone-suspicious-realloc-usage
This diagnostic finds instances of realloc that take the form:
`p = realloc(p, size);`
The issue here is that, if realloc fails for any reason, there will can a memory leak—`p` becomes a null pointer but the memory it points to is not deallocated. (This is simple to fix with the form `g = realloc(p, size);`.)
This check triggers 22 times in Chromium, primarily in various third_party libraries (
example,
example,
example). I didn't find any false positives; it seems the check is relatively narrowly tailored to catch this specific type of misuse.
Given both of these warnings trigger relatively infrequently but catch real bugs/problems I'd like to enable them both.
The CL for these changes is
here & I welcome any feedback. Thanks!