mirror of https://github.com/xzeldon/htop.git
Replace size_t with int/void* union
I was occasionally passing negative values to size_t. Plus, this better reflects the intent of the variant argument. Reported by Coverity: https://scan8.coverity.com/reports.htm#v13253/p10402/fileInstanceId=22093891&defectInstanceId=7543346&mergedDefectId=174179&fileStart=251&fileEnd=500
This commit is contained in:
parent
b064d501ae
commit
8c653212c0
6
Action.c
6
Action.c
|
@ -115,7 +115,7 @@ static void Action_runSetup(Settings* settings, const Header* header, ProcessLis
|
|||
|
||||
static bool changePriority(MainPanel* panel, int delta) {
|
||||
bool anyTagged;
|
||||
bool ok = MainPanel_foreachProcess(panel, (MainPanel_ForeachProcessFn) Process_changePriorityBy, delta, &anyTagged);
|
||||
bool ok = MainPanel_foreachProcess(panel, (MainPanel_ForeachProcessFn) Process_changePriorityBy, (Arg){ .i = delta }, &anyTagged);
|
||||
if (!ok)
|
||||
beep();
|
||||
return anyTagged;
|
||||
|
@ -285,7 +285,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
|
|||
void* set = Action_pickFromVector(st, affinityPanel, 15);
|
||||
if (set) {
|
||||
Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl);
|
||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (size_t) affinity, NULL);
|
||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity }, NULL);
|
||||
if (!ok) beep();
|
||||
Affinity_delete(affinity);
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ static Htop_Reaction actionKill(State* st) {
|
|||
Panel_setHeader(st->panel, "Sending...");
|
||||
Panel_draw(st->panel, true);
|
||||
refresh();
|
||||
MainPanel_foreachProcess((MainPanel*)st->panel, (MainPanel_ForeachProcessFn) Process_sendSignal, (size_t) sgn->key, NULL);
|
||||
MainPanel_foreachProcess((MainPanel*)st->panel, (MainPanel_ForeachProcessFn) Process_sendSignal, (Arg){ .i = sgn->key }, NULL);
|
||||
napms(500);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,8 +115,9 @@ void InfoScreen_run(InfoScreen* this) {
|
|||
|
||||
Panel_draw(panel, true);
|
||||
|
||||
if (this->inc->active)
|
||||
move(LINES-1, CRT_cursorX);
|
||||
if (this->inc->active) {
|
||||
(void) move(LINES-1, CRT_cursorX);
|
||||
}
|
||||
set_escdelay(25);
|
||||
int ch = getch();
|
||||
|
||||
|
|
|
@ -25,7 +25,12 @@ typedef struct MainPanel_ {
|
|||
pid_t pidSearch;
|
||||
} MainPanel;
|
||||
|
||||
typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
|
||||
typedef union {
|
||||
int i;
|
||||
void* v;
|
||||
} Arg;
|
||||
|
||||
typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg);
|
||||
|
||||
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
||||
|
||||
|
@ -148,7 +153,7 @@ const char* MainPanel_getValue(MainPanel* this, int i) {
|
|||
return "";
|
||||
}
|
||||
|
||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, size_t arg, bool* wasAnyTagged) {
|
||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged) {
|
||||
Panel* super = (Panel*) this;
|
||||
bool ok = true;
|
||||
bool anyTagged = false;
|
||||
|
|
|
@ -21,7 +21,12 @@ typedef struct MainPanel_ {
|
|||
pid_t pidSearch;
|
||||
} MainPanel;
|
||||
|
||||
typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
|
||||
typedef union {
|
||||
int i;
|
||||
void* v;
|
||||
} Arg;
|
||||
|
||||
typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg);
|
||||
|
||||
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
||||
|
||||
|
@ -34,7 +39,7 @@ int MainPanel_selectedPid(MainPanel* this);
|
|||
|
||||
const char* MainPanel_getValue(MainPanel* this, int i);
|
||||
|
||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, size_t arg, bool* wasAnyTagged);
|
||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged);
|
||||
|
||||
extern PanelClass MainPanel_class;
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ void OpenFilesScreen_scan(InfoScreen* this) {
|
|||
char** data = fdata->data.data;
|
||||
int lenN = data['n'] ? strlen(data['n']) : 0;
|
||||
int sizeEntry = 5 + 7 + 10 + 10 + 10 + lenN + 5 /*spaces*/ + 1 /*null*/;
|
||||
char* entry = xMalloc(sizeEntry);
|
||||
char entry[sizeEntry];
|
||||
xSnprintf(entry, sizeEntry, "%5.5s %7.7s %10.10s %10.10s %10.10s %s",
|
||||
data['f'] ? data['f'] : "",
|
||||
data['t'] ? data['t'] : "",
|
||||
|
|
|
@ -536,11 +536,11 @@ bool Process_setPriority(Process* this, int priority) {
|
|||
return (err == 0);
|
||||
}
|
||||
|
||||
bool Process_changePriorityBy(Process* this, size_t delta) {
|
||||
bool Process_changePriorityBy(Process* this, int delta) {
|
||||
return Process_setPriority(this, this->nice + delta);
|
||||
}
|
||||
|
||||
void Process_sendSignal(Process* this, size_t sgn) {
|
||||
void Process_sendSignal(Process* this, int sgn) {
|
||||
CRT_dropPrivileges();
|
||||
kill(this->pid, (int) sgn);
|
||||
CRT_restorePrivileges();
|
||||
|
|
|
@ -190,9 +190,9 @@ void Process_toggleTag(Process* this);
|
|||
|
||||
bool Process_setPriority(Process* this, int priority);
|
||||
|
||||
bool Process_changePriorityBy(Process* this, size_t delta);
|
||||
bool Process_changePriorityBy(Process* this, int delta);
|
||||
|
||||
void Process_sendSignal(Process* this, size_t sgn);
|
||||
void Process_sendSignal(Process* this, int sgn);
|
||||
|
||||
long Process_pidCompare(const void* v1, const void* v2);
|
||||
|
||||
|
|
|
@ -108,7 +108,8 @@ bool TraceScreen_forkTracer(TraceScreen* this) {
|
|||
(void) written;
|
||||
exit(1);
|
||||
}
|
||||
fcntl(this->fdpair[0], F_SETFL, O_NONBLOCK);
|
||||
int ok = fcntl(this->fdpair[0], F_SETFL, O_NONBLOCK);
|
||||
if (ok == -1) return false;
|
||||
this->strace = fdopen(this->fdpair[0], "r");
|
||||
this->fd_strace = fileno(this->strace);
|
||||
return true;
|
||||
|
|
|
@ -96,7 +96,7 @@ static Htop_Reaction Platform_actionSetIOPriority(State* st) {
|
|||
void* set = Action_pickFromVector(st, ioprioPanel, 21);
|
||||
if (set) {
|
||||
IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel);
|
||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (size_t) ioprio, NULL);
|
||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (Arg){ .i = ioprio }, NULL);
|
||||
if (!ok)
|
||||
beep();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue