]> granicus.if.org Git - procps-ng/commit
top: circumvent a false positive smatch error
authorJim Warner <james.warner@comcast.net>
Thu, 8 Dec 2011 19:13:59 +0000 (13:13 -0600)
committerCraig Small <csmall@enc.com.au>
Sun, 11 Dec 2011 11:28:03 +0000 (22:28 +1100)
commit1e4447d171c46143840ea4ab5443323a87cc1668
tree58911bafab18e975599664df9b4cbe41c49434d2
parentcd608f462e587ee648f4bd0b798e77a52dd66c13
top: circumvent a false positive smatch error

  The smatch error --------------
top.c +1414 calibrate_fields(78) error: buffer overflow 'Fieldstab' 39 <= 39

  The code -----------------------
if (P_MAXPFLGS < f) { w->endpflg = i; continue; }

  The background -----------------
The enum P_MAXPFLGS is strictly a fencepost and can *never* appear in
the arrays pflgsall or procflgs.  Thus it (39th element) cannot be used
in referencing Fieldstab.

However, two enums of higher value (X_XON=40 and X_XOF=41) *can* appear
in those arrays.  But the test against the fencepost ensures that those
two enums are *never* used in referencing Fieldstab.

When the analyzer sees the conditional using '<' and not '<='
it reports a false positive.

The source was changed to accommodate the tool's deficiency
top.c