mirror of https://github.com/xzeldon/htop.git
Handle Panel_getSelected() returning NULL
Found by compiling with LTO: ColumnsPanel.c: In function ‘ColumnsPanel_eventHandler’: ColumnsPanel.c:46:59: error: potential null pointer dereference [-Werror=null-dereference] 46 | ((ListItem*)Panel_getSelected(super))->moving = this->moving; | ^ AvailableColumnsPanel.c: In function ‘AvailableColumnsPanel_eventHandler’: AvailableColumnsPanel.c:31:8: error: potential null pointer dereference [-Werror=null-dereference] 31 | int key = ((ListItem*) Panel_getSelected(super))->key; | ^ AvailableMetersPanel.c: In function ‘AvailableMetersPanel_eventHandler’: AvailableMetersPanel.c:40:24: error: potential null pointer dereference [-Werror=null-dereference] 40 | int param = selected->key & 0xff; | ^ linux/IOPriorityPanel.c: In function ‘IOPriorityPanel_getIOPriority’: linux/IOPriorityPanel.c:37:11: error: potential null pointer dereference [-Werror=null-dereference] 37 | return (IOPriority) ( ((ListItem*) Panel_getSelected(this))->key ); | ^
This commit is contained in:
parent
e9fa290019
commit
ad3acfc847
|
@ -28,7 +28,6 @@ static void AvailableColumnsPanel_delete(Object* object) {
|
||||||
|
|
||||||
static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
|
static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||||
AvailableColumnsPanel* this = (AvailableColumnsPanel*) super;
|
AvailableColumnsPanel* this = (AvailableColumnsPanel*) super;
|
||||||
int key = ((ListItem*) Panel_getSelected(super))->key;
|
|
||||||
HandlerResult result = IGNORED;
|
HandlerResult result = IGNORED;
|
||||||
|
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
|
@ -36,6 +35,11 @@ static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||||
case KEY_ENTER:
|
case KEY_ENTER:
|
||||||
case KEY_F(5):
|
case KEY_F(5):
|
||||||
{
|
{
|
||||||
|
const ListItem* selected = (ListItem*) Panel_getSelected(super);
|
||||||
|
if (!selected)
|
||||||
|
break;
|
||||||
|
|
||||||
|
int key = selected->key;
|
||||||
int at = Panel_getSelectedIndex(this->columns);
|
int at = Panel_getSelectedIndex(this->columns);
|
||||||
Panel_insert(this->columns, at, (Object*) ListItem_new(Process_fields[key].name, key));
|
Panel_insert(this->columns, at, (Object*) ListItem_new(Process_fields[key].name, key));
|
||||||
Panel_setSelected(this->columns, at+1);
|
Panel_setSelected(this->columns, at+1);
|
||||||
|
|
|
@ -36,7 +36,10 @@ static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {
|
||||||
AvailableMetersPanel* this = (AvailableMetersPanel*) super;
|
AvailableMetersPanel* this = (AvailableMetersPanel*) super;
|
||||||
Header* header = this->header;
|
Header* header = this->header;
|
||||||
|
|
||||||
ListItem* selected = (ListItem*) Panel_getSelected(super);
|
const ListItem* selected = (ListItem*) Panel_getSelected(super);
|
||||||
|
if (!selected)
|
||||||
|
return IGNORED;
|
||||||
|
|
||||||
int param = selected->key & 0xff;
|
int param = selected->key & 0xff;
|
||||||
int type = selected->key >> 16;
|
int type = selected->key >> 16;
|
||||||
HandlerResult result = IGNORED;
|
HandlerResult result = IGNORED;
|
||||||
|
|
|
@ -43,7 +43,9 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||||
if (selected < size - 1) {
|
if (selected < size - 1) {
|
||||||
this->moving = !(this->moving);
|
this->moving = !(this->moving);
|
||||||
Panel_setSelectionColor(super, this->moving ? CRT_colors[PANEL_SELECTION_FOLLOW] : CRT_colors[PANEL_SELECTION_FOCUS]);
|
Panel_setSelectionColor(super, this->moving ? CRT_colors[PANEL_SELECTION_FOLLOW] : CRT_colors[PANEL_SELECTION_FOCUS]);
|
||||||
((ListItem*)Panel_getSelected(super))->moving = this->moving;
|
ListItem* selectedItem = (ListItem*) Panel_getSelected(super);
|
||||||
|
if (selectedItem)
|
||||||
|
selectedItem->moving = this->moving;
|
||||||
result = HANDLED;
|
result = HANDLED;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -34,5 +34,6 @@ Panel* IOPriorityPanel_new(IOPriority currPrio) {
|
||||||
}
|
}
|
||||||
|
|
||||||
IOPriority IOPriorityPanel_getIOPriority(Panel* this) {
|
IOPriority IOPriorityPanel_getIOPriority(Panel* this) {
|
||||||
return (IOPriority) ( ((ListItem*) Panel_getSelected(this))->key );
|
const ListItem* selected = (ListItem*) Panel_getSelected(this);
|
||||||
|
return selected ? selected->key : IOPriority_None;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue