summaryrefslogtreecommitdiffstats
path: root/source/widgets
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-10-17 18:21:03 +0200
committerDave Davenport <qball@gmpclient.org>2016-10-17 18:21:03 +0200
commit0e176199fcc05cf0eac3d43e0e4d9e679a74960c (patch)
treeaad4c72d5336270d84f1a92cb8cac98f0193664f /source/widgets
parent313dffa28dd1cc6a902c0becd4f1b1115a3a807e (diff)
Fix some possible null pointer dereference. (clang-check)
Diffstat (limited to 'source/widgets')
-rw-r--r--source/widgets/box.c1
-rw-r--r--source/widgets/listview.c10
-rw-r--r--source/widgets/widget.c14
3 files changed, 20 insertions, 5 deletions
diff --git a/source/widgets/box.c b/source/widgets/box.c
index 8aec12b1..6f5b12de 100644
--- a/source/widgets/box.c
+++ b/source/widgets/box.c
@@ -208,6 +208,7 @@ static void box_free ( widget *wid )
void box_add ( box *box, widget *child, gboolean expand, gboolean end )
{
+ if ( box == NULL ) return;
child->expand = expand;
child->end = end;
child->parent = WIDGET ( box );
diff --git a/source/widgets/listview.c b/source/widgets/listview.c
index a5184a18..055be2f6 100644
--- a/source/widgets/listview.c
+++ b/source/widgets/listview.c
@@ -151,7 +151,7 @@ static void listview_draw ( widget *wid, cairo_t *draw )
unsigned int width = lv->widget.w - lv->padding * ( lv->cur_columns - 1 );
if ( widget_enabled ( WIDGET ( lv->scrollbar ) ) ) {
width -= lv->padding;
- width -= lv->scrollbar->widget.w;
+ width -= widget_get_width ( WIDGET ( lv->scrollbar ) );
}
unsigned int element_width = ( width ) / lv->cur_columns;
for ( unsigned int i = 0; i < max; i++ ) {
@@ -237,8 +237,8 @@ static void listview_resize ( widget *wid, short w, short h )
lv->max_rows = ( lv->padding + lv->widget.h ) / ( lv->element_height + lv->padding );
lv->max_elements = lv->max_rows * lv->menu_columns;
- widget_move ( WIDGET ( lv->scrollbar ), lv->widget.w - lv->scrollbar->widget.w, 0 );
- widget_resize ( WIDGET ( lv->scrollbar ), lv->scrollbar->widget.w, h );
+ widget_move ( WIDGET ( lv->scrollbar ), lv->widget.w - widget_get_width ( WIDGET (lv->scrollbar ) ), 0 );
+ widget_resize ( WIDGET ( lv->scrollbar ), widget_get_width ( WIDGET ( lv->scrollbar ) ), h );
listview_recompute_elements ( lv );
widget_queue_redraw ( wid );
@@ -260,8 +260,8 @@ static gboolean listview_clicked ( widget *wid, xcb_button_press_event_t *xce, G
if ( widget_enabled ( WIDGET ( lv->scrollbar ) ) && widget_intersect ( WIDGET ( lv->scrollbar ), xce->event_x, xce->event_y ) ) {
// Forward to handler of scrollbar.
xcb_button_press_event_t xce2 = *xce;
- xce->event_x -= lv->scrollbar->widget.x;
- xce->event_y -= lv->scrollbar->widget.y;
+ xce->event_x -= widget_get_x_pos ( WIDGET ( lv->scrollbar ) );
+ xce->event_y -= widget_get_y_pos ( WIDGET ( lv->scrollbar ) );
return widget_clicked ( WIDGET ( lv->scrollbar ), &xce2 );
}
// Handle the boxes.
diff --git a/source/widgets/widget.c b/source/widgets/widget.c
index 916ce61c..48642cb7 100644
--- a/source/widgets/widget.c
+++ b/source/widgets/widget.c
@@ -93,6 +93,20 @@ int widget_get_width ( widget *widget )
}
return 0;
}
+int widget_get_x_pos ( widget *widget )
+{
+ if ( widget ) {
+ return widget->x;
+ }
+ return 0;
+}
+int widget_get_y_pos ( widget *widget )
+{
+ if ( widget ) {
+ return widget->y;
+ }
+ return 0;
+}
void widget_update ( widget *widget )
{