Use 0 as no-match value for sortkey

Field numbers start at 1, and using -1 as no-match special value triggers
static analyzers using a potential negative array access.
This commit is contained in:
Christian Göttsche 2020-11-16 16:59:01 +01:00
parent f38af725c2
commit b3b890f546
1 changed files with 2 additions and 2 deletions

4
htop.c
View File

@ -139,7 +139,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
}
exit(0);
}
flags.sortKey = -1;
flags.sortKey = 0;
for (int j = 1; j < Platform_numberOfFields; j++) {
if (Process_fields[j].name == NULL)
continue;
@ -148,7 +148,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
break;
}
}
if (flags.sortKey == -1) {
if (flags.sortKey == 0) {
fprintf(stderr, "Error: invalid column \"%s\".\n", optarg);
exit(1);
}