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
This commit is contained in:
parent
cd608f462e
commit
1e4447d171
2
top.c
2
top.c
@ -1409,7 +1409,7 @@ static void calibrate_fields (void) {
|
||||
for (i = w->totpflgs - 1; -1 < i; i--) {
|
||||
f = w->pflgsall[i];
|
||||
#ifndef USE_X_COLHDR
|
||||
if (P_MAXPFLGS < f) { w->endpflg = i; continue; }
|
||||
if (P_MAXPFLGS <= f) { w->endpflg = i; continue; }
|
||||
#endif
|
||||
h = Fieldstab[f].head;
|
||||
if (Screen_cols < ((int)(s - w->columnhdr) + (int)strlen(h))) break;
|
||||
|
Loading…
Reference in New Issue
Block a user