cgtop: fix sscanf return code checks

sscanf can return EOF on error, so check that we get a result instead.

CodeQL#2386 and CodeQL#2387
This commit is contained in:
Luca Boccassi 2024-01-19 15:12:49 +00:00 committed by Luca Boccassi
parent 201f6241ae
commit 204d52c4b7

View file

@ -310,9 +310,9 @@ static int process(
if (all_unified) {
while (!isempty(l)) {
if (sscanf(l, "rbytes=%" SCNu64, &k))
if (sscanf(l, "rbytes=%" SCNu64, &k) == 1)
rd += k;
else if (sscanf(l, "wbytes=%" SCNu64, &k))
else if (sscanf(l, "wbytes=%" SCNu64, &k) == 1)
wr += k;
l += strcspn(l, WHITESPACE);