Fix some possible null pointer dereference. (clang-check)

This commit is contained in:
Dave Davenport 2016-10-17 18:21:03 +02:00
parent 313dffa28d
commit 0e176199fc
4 changed files with 34 additions and 5 deletions

View File

@ -108,6 +108,20 @@ int widget_get_height ( widget *widget );
*/
int widget_get_width ( widget *widget );
/**
* @param widget The widget handle
*
* @returns the y postion of the widget relative to its parent.
*/
int widget_get_y_pos ( widget *widget );
/**
* @param widget The widget handle
*
* @returns the x postion of the widget relative to its parent.
*/
int widget_get_x_pos ( widget *widget );
/**
* @param widget The widget handle
*

View File

@ -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 );

View File

@ -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.

View File

@ -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 )
{