Make clang happier
authorMikael Magnusson <mikachu@gmail.com>
Thu, 5 Nov 2009 21:27:47 +0000 (22:27 +0100)
committerMikael Magnusson <mikachu@gmail.com>
Thu, 5 Nov 2009 21:27:47 +0000 (22:27 +0100)
Add asserts to default: in switch statements
Store pointed to variables locally so it knows they don't change
Remove some dead assignments
Mark ob_exit_with_error as noreturn

13 files changed:
openbox/actions/desktop.c
openbox/actions/moverelative.c
openbox/actions/session.c
openbox/client.c
openbox/config.c
openbox/event.c
openbox/focus_cycle_popup.c
openbox/menuframe.c
openbox/moveresize.c
openbox/openbox.h
openbox/popup.c
openbox/stacking.c
render/font.c

index 29aff1358a40d2d6e25befddd84d31f8869639f2..7b5db41265415a533d68706751f4993aa890269f 100644 (file)
@@ -185,6 +185,8 @@ static gboolean run_func(ObActionsData *data, gpointer options)
         d = screen_find_desktop(screen_desktop,
                                 o->u.rel.dir, o->u.rel.wrap, o->u.rel.linear);
         break;
+    default:
+        g_assert_not_reached();
     }
 
     if (d < screen_num_desktops &&
index e923858318442f42e7d3ae49f850aa6669adddd6..a903fae9a6b3fe959c93706cce0679e3aab60046 100644 (file)
@@ -42,15 +42,15 @@ static gboolean run_func(ObActionsData *data, gpointer options)
         gint x, y, lw, lh, w, h;
 
         c = data->client;
-        x = data->client->area.x + o->x;
-        y = data->client->area.y + o->y;
-        w = data->client->area.width;
-        h = data->client->area.height;
-        client_try_configure(data->client, &x, &y, &w, &h, &lw, &lh, TRUE);
-        client_find_onscreen(data->client, &x, &y, w, h, FALSE);
+        x = c->area.x + o->x;
+        y = c->area.y + o->y;
+        w = c->area.width;
+        h = c->area.height;
+        client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
+        client_find_onscreen(c, &x, &y, w, h, FALSE);
 
         actions_client_move(data, TRUE);
-        client_configure(data->client, x, y, w, h, TRUE, TRUE, FALSE);
+        client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
         actions_client_move(data, FALSE);
     }
 
index e9cc40dbbd4e780acae71c21cf1f524f81528016..88dd3177ce45eabd2daa5d24e917019711725cd6 100644 (file)
@@ -33,9 +33,9 @@ static gpointer setup_func(xmlNodePtr node)
 
 static gboolean prompt_cb(ObPrompt *p, gint result, gpointer data)
 {
-    Options *o = data;
     if (result) {
 #ifdef USE_SM
+        Options *o = data;
         session_request_logout(o->silent);
 #else
         /* TRANSLATORS: Don't translate the word "SessionLogout" as it's the
index 42d8c6e119c57a20f51693d76ef20307fcea2794..3e841d52721819967a61328093ad429e1ef11c58 100644 (file)
@@ -3643,6 +3643,8 @@ void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
                 value = undecorated;
             else if (state == OBT_PROP_ATOM(OB_WM_STATE_LOCKED))
                 value = locked;
+            else
+                g_assert_not_reached();
             action = value ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
                              OBT_PROP_ATOM(NET_WM_STATE_ADD);
         }
index 2a96e2d7cf16e3ef6f413196a4a31207206d847a..5ad19a083abb81fc6add9c63d277f2263652a881 100644 (file)
@@ -204,7 +204,7 @@ static void parse_per_app_settings(xmlNodePtr node, gpointer d)
     gboolean x_pos_given;
 
     while (app) {
-        name_set = class_set = type_set = x_pos_given = FALSE;
+        x_pos_given = FALSE;
 
         class_set = obt_parse_attr_string(app, "class", &class);
         name_set = obt_parse_attr_string(app, "name", &name);
index c9b9dca6eac6cb34270c81f0008d9a1664f02dfa..6c69e499be5bf1e0c6071a3ec7cfe9bbea39d441 100644 (file)
@@ -420,6 +420,7 @@ static void print_focusevent(XEvent *e)
     case NotifyGrab:         modestr="NotifyGrab";         break;
     case NotifyUngrab:       modestr="NotifyUngrab";       break;
     case NotifyWhileGrabbed: modestr="NotifyWhileGrabbed"; break;
+    default:                 g_assert_not_reached();
     }
     switch (detail) {
     case NotifyAncestor:    detailstr="NotifyAncestor";    break;
@@ -430,6 +431,7 @@ static void print_focusevent(XEvent *e)
     case NotifyPointer:     detailstr="NotifyPointer";     break;
     case NotifyPointerRoot: detailstr="NotifyPointerRoot"; break;
     case NotifyDetailNone:  detailstr="NotifyDetailNone";  break;
+    default:                g_assert_not_reached();
     }
 
     if (mode == NotifyGrab || mode == NotifyUngrab)
@@ -1623,6 +1625,8 @@ static void event_handle_client(ObClient *client, XEvent *e)
                         client->shaped_input = ((XShapeEvent*)e)->shaped;
                         kind = ShapeInput;
                         break;
+                    default:
+                        g_assert_not_reached();
                 }
                 frame_adjust_shape_kind(client->frame, kind);
             }
index 3ac51b93b8a6575087186ac42787f87c9d8f3512..8a87f667600b426db1bbfc277f231e26790ded81 100644 (file)
@@ -329,6 +329,7 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
     gint i;
     GList *it;
     const ObFocusCyclePopupTarget *newtarget;
+    ObFocusCyclePopupMode mode = p->mode;
     gint icons_per_row;
     gint icon_rows;
     gint textw, texth;
@@ -346,8 +347,8 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
     gint up_arrow_y, down_arrow_y;
     gboolean showing_arrows = FALSE;
 
-    g_assert(p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ||
-             p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST);
+    g_assert(mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ||
+             mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST);
 
     screen_area = screen_physical_area_active();
 
@@ -362,7 +363,7 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
 
     /* get the width from the text and keep it within limits */
     w = l + r + p->maxtextw;
-    if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
+    if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
         /* when in list mode, there are icons down the side */
         w += list_mode_icon_column_w;
     w = MIN(w, MAX(screen_area->width/3, POPUP_WIDTH)); /* max width */
@@ -370,12 +371,12 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
 
     /* get the text height */
     texth = RrMinHeight(p->a_hilite_text);
-    if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
+    if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
         texth = MAX(MAX(texth, RrMinHeight(p->a_text)), HILITE_SIZE);
     else
         texth += TEXT_BORDER * 2;
 
-    if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) {
+    if (mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) {
         /* how many icons will fit in that row? make the width fit that */
         w -= l + r;
         icons_per_row = (w + HILITE_SIZE - 1) / HILITE_SIZE;
@@ -397,7 +398,7 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
 
     /* get the text width */
     textw = w - l - r;
-    if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
+    if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
         /* leave space on the side for the icons */
         textw -= list_mode_icon_column_w;
 
@@ -407,7 +408,7 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
 
     /* find the height of the dialog */
     h = t + b + (icon_rows * MAX(HILITE_SIZE, texth));
-    if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS)
+    if (mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS)
         /* in icon mode the text sits below the icons, so make some space */
         h += OUTSIDE_BORDER + texth;
 
@@ -426,7 +427,7 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
 
     /* scroll the list if needed */
     last_scroll = p->scroll;
-    if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) {
+    if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) {
         const gint top = p->scroll + SCROLL_MARGIN;
         const gint bottom = p->scroll + icon_rows - SCROLL_MARGIN;
         const gint min_scroll = 0;
@@ -442,14 +443,14 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
     }
 
     /* show the scroll arrows when appropriate */
-    if (p->scroll && p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) {
+    if (p->scroll && mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) {
         XMapWindow(obt_display, p->list_mode_up);
         showing_arrows = TRUE;
     } else
         XUnmapWindow(obt_display, p->list_mode_up);
 
     if (p->scroll < p->n_targets - icon_rows &&
-        p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
+        mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
     {
         XMapWindow(obt_display, p->list_mode_down);
         showing_arrows = TRUE;
@@ -462,12 +463,12 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
             + ob_rr_theme->down_arrow_mask->height + OUTSIDE_BORDER;
 
     /* center the icons if there is less than one row */
-    if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS && icon_rows == 1)
+    if (mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS && icon_rows == 1)
         icons_center_x = (w - p->n_targets * HILITE_SIZE) / 2;
     else
         icons_center_x = 0;
 
-    if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) {
+    if (mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) {
         /* get the position of the text */
         icon_mode_textx = l;
         icon_mode_texty = h - texth - b;
@@ -483,7 +484,7 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
         /* position the background but don't draw it */
         XMoveResizeWindow(obt_display, p->bg, x, y, w, h);
 
-        if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) {
+        if (mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) {
             /* position the text */
             XMoveResizeWindow(obt_display, p->icon_mode_text,
                               icon_mode_textx, icon_mode_texty, textw, texth);
@@ -516,7 +517,7 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
         RrPaint(p->a_bg, p->bg, w, h);
 
     /* draw the scroll arrows */
-    if (!p->mapped && p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) {
+    if (!p->mapped && mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) {
         p->a_arrow->texture[0].data.mask.mask =
             ob_rr_theme->up_arrow_mask;
         p->a_arrow->surface.parent = p->a_bg;
@@ -569,7 +570,7 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
                               iconx, icony, HILITE_SIZE, HILITE_SIZE);
 
             /* position the text */
-            if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
+            if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
                 XMoveResizeWindow(obt_display, target->textwin,
                                   list_mode_textx, list_mode_texty,
                                   textw, texth);
@@ -577,13 +578,13 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
             /* show/hide the right windows */
             if (row >= 0 && row < icon_rows) {
                 XMapWindow(obt_display, target->iconwin);
-                if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
+                if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
                     XMapWindow(obt_display, target->textwin);
                 else
                     XUnmapWindow(obt_display, target->textwin);
             } else {
                 XUnmapWindow(obt_display, target->textwin);
-                if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
+                if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
                     XUnmapWindow(obt_display, target->iconwin);
                 else
                     XMapWindow(obt_display, target->iconwin);
@@ -608,19 +609,19 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
             RrPaint(p->a_icon, target->iconwin, HILITE_SIZE, HILITE_SIZE);
 
             /* draw the text */
-            if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST ||
+            if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST ||
                 target == newtarget)
             {
                 text = (target == newtarget) ? p->a_hilite_text : p->a_text;
                 text->texture[0].data.text.string = target->text;
                 text->surface.parentx =
-                    p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ?
+                    mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ?
                     icon_mode_textx : list_mode_textx;
                 text->surface.parenty =
-                    p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ?
+                    mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ?
                     icon_mode_texty : list_mode_texty;
                 RrPaint(text,
-                        (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ?
+                        (mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ?
                          p->icon_mode_text : target->textwin),
                         textw, texth);
             }
index f2a58765efe6bb74d101e39af8c457f47b243355..040bf0713cb498b061f18838a83fe0e2beba15a8 100644 (file)
@@ -388,7 +388,7 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self)
                   ob_rr_theme->a_menu_text_normal);
         sub = self->entry->data.submenu.submenu;
         text_a->texture[0].data.text.string = sub ? sub->title : "";
-        if (sub->shortcut && (self->frame->menu->show_all_shortcuts ||
+        if (sub && sub->shortcut && (self->frame->menu->show_all_shortcuts ||
                               sub->shortcut_always_show ||
                               sub->shortcut_position > 0))
         {
@@ -406,6 +406,8 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self)
         else
             text_a = ob_rr_theme->a_menu_text_normal;
         break;
+    default:
+        g_assert_not_reached();
     }
 
     /* Draw the text, dunno why this is separate from the above? */
@@ -475,6 +477,8 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self)
                     2*ob_rr_theme->menu_sep_paddingy);
         }
         break;
+    default:
+        g_assert_not_reached();
     }
 
     /* draw a color icon */
@@ -749,6 +753,8 @@ void menu_frame_render(ObMenuFrame *self)
                     2*ob_rr_theme->menu_sep_paddingy - 2*PADDING;
             }
             break;
+        default:
+            g_assert_not_reached();
         }
         tw += 2*PADDING;
         th += 2*PADDING;
index b45df742aba4ef7b1220473b7a4cd24774075ee5..76194838c19ecd8cb4de261e7fc2d0bf37258fbc 100644 (file)
@@ -665,7 +665,7 @@ static void move_with_keys(gint keycode, gint state)
 static void resize_with_keys(gint keycode, gint state)
 {
     gint dw = 0, dh = 0, pdx = 0, pdy = 0, opx, opy, px, py;
-    gint dist = 0, resist = 0;
+    gint resist = 0;
     ObDirection dir;
 
     /* pick the edge if it needs to move */
@@ -677,8 +677,7 @@ static void resize_with_keys(gint keycode, gint state)
             key_resize_edge = OB_DIRECTION_EAST;
             return;
         }
-    }
-    if (keycode == ob_keycode(OB_KEY_LEFT)) {
+    } else if (keycode == ob_keycode(OB_KEY_LEFT)) {
         dir = OB_DIRECTION_WEST;
         if (key_resize_edge != OB_DIRECTION_WEST &&
             key_resize_edge != OB_DIRECTION_EAST)
@@ -686,8 +685,7 @@ static void resize_with_keys(gint keycode, gint state)
             key_resize_edge = OB_DIRECTION_WEST;
             return;
         }
-    }
-    if (keycode == ob_keycode(OB_KEY_UP)) {
+    } else if (keycode == ob_keycode(OB_KEY_UP)) {
         dir = OB_DIRECTION_NORTH;
         if (key_resize_edge != OB_DIRECTION_NORTH &&
             key_resize_edge != OB_DIRECTION_SOUTH)
@@ -695,8 +693,7 @@ static void resize_with_keys(gint keycode, gint state)
             key_resize_edge = OB_DIRECTION_NORTH;
             return;
         }
-    }
-    if (keycode == ob_keycode(OB_KEY_DOWN)) {
+    } else /* if (keycode == ob_keycode(OB_KEY_DOWN)) */ {
         dir = OB_DIRECTION_SOUTH;
         if (key_resize_edge != OB_DIRECTION_NORTH &&
             key_resize_edge != OB_DIRECTION_SOUTH)
@@ -759,27 +756,27 @@ static void resize_with_keys(gint keycode, gint state)
 
         if (key_resize_edge == OB_DIRECTION_WEST) {
             if (dir == OB_DIRECTION_WEST)
-                dw = (dist = distw);
+                dw = distw;
             else
-                dw = -(dist = distw);
+                dw = -distw;
         }
         else if (key_resize_edge == OB_DIRECTION_EAST) {
             if (dir == OB_DIRECTION_EAST)
-                dw = (dist = distw);
+                dw = distw;
             else
-                dw = -(dist = distw);
+                dw = -distw;
         }
         else if (key_resize_edge == OB_DIRECTION_NORTH) {
             if (dir == OB_DIRECTION_NORTH)
-                dh = (dist = disth);
+                dh = disth;
             else
-                dh = -(dist = disth);
+                dh = -disth;
         }
         else /*if (key_resize_edge == OB_DIRECTION_SOUTH)*/ {
             if (dir == OB_DIRECTION_SOUTH)
-                dh = (dist = disth);
+                dh = disth;
             else
-                dh = -(dist = disth);
+                dh = -disth;
         }
     }
 
index 2a938c5d1154edc4e02a3529f3e22776b6034bfa..b2e9c4cbd0a4513d73ca08415ac30b21eea2a136 100644 (file)
@@ -58,7 +58,7 @@ void ob_exit_replace(void);
 
 void ob_reconfigure(void);
 
-void ob_exit_with_error(const gchar *msg);
+void ob_exit_with_error(const gchar *msg) G_GNUC_NORETURN;
 
 Cursor ob_cursor(ObCursor cursor);
 
index 4a5a8e0725cd85f024fb0112406e409a3b565c6a..1ed57848e44a07f64d8db8c21525424660fdd414 100644 (file)
@@ -157,11 +157,12 @@ void popup_delay_show(ObPopup *self, gulong usec, gchar *text)
     gint textx, texty, textw, texth;
     gint iconx, icony, iconw, iconh;
     Rect *area, mon;
+    gboolean hasicon = self->hasicon;
 
     /* when there is no icon and the text is not parent relative, then
        fill the whole dialog with the text appearance, don't use the bg at all
     */
-    if (self->hasicon || self->a_text->surface.grad == RR_SURFACE_PARENTREL)
+    if (hasicon || self->a_text->surface.grad == RR_SURFACE_PARENTREL)
         RrMargins(self->a_bg, &l, &t, &r, &b);
     else
         l = t = r = b = 0;
@@ -189,7 +190,7 @@ void popup_delay_show(ObPopup *self, gulong usec, gchar *text)
     iconx = textx = l + ob_rr_theme->paddingx;
 
     emptyx = l + r + ob_rr_theme->paddingx * 2;
-    if (self->hasicon) {
+    if (hasicon) {
         iconw = texth * self->iconwm;
         iconh = texth * self->iconhm;
         textx += iconw + ob_rr_theme->paddingx;
@@ -204,7 +205,7 @@ void popup_delay_show(ObPopup *self, gulong usec, gchar *text)
     /* when there is no icon, then fill the whole dialog with the text
        appearance
     */
-    if (!self->hasicon)
+    if (!hasicon)
     {
         textx = texty = 0;
         texth += emptyy;
@@ -279,7 +280,7 @@ void popup_delay_show(ObPopup *self, gulong usec, gchar *text)
     /* when there is no icon and the text is not parent relative, then
        fill the whole dialog with the text appearance, don't use the bg at all
     */
-    if (self->hasicon || self->a_text->surface.grad == RR_SURFACE_PARENTREL)
+    if (hasicon || self->a_text->surface.grad == RR_SURFACE_PARENTREL)
         RrPaint(self->a_bg, self->bg, w, h);
 
     if (textw) {
@@ -290,7 +291,7 @@ void popup_delay_show(ObPopup *self, gulong usec, gchar *text)
         RrPaint(self->a_text, self->text, textw, texth);
     }
 
-    if (self->hasicon)
+    if (hasicon)
         self->draw_icon(iconx, icony, iconw, iconh, self->draw_icon_data);
 
     /* do the actual showing */
index 3c05df49c64c0c23f470a87aa4e090ee33fb4d29..2a34f71dc4eea10305c1037a0ae24b64d9d4025b 100644 (file)
@@ -69,6 +69,8 @@ static void do_restack(GList *wins, GList *before)
 
 #ifdef DEBUG
     GList *next;
+
+    g_assert(wins);
     /* pls only restack stuff in the same layer at a time */
     for (it = wins; it; it = next) {
         next = g_list_next(it);
index ff8852b9ffd102b1b72ee3e7ef3d53a4bfe84346..fde50c6a16c3f310e2c7e1cd5cd253aec4f39339 100644 (file)
@@ -226,7 +226,7 @@ static inline int font_calculate_baseline(RrFont *f, gint height)
 
 void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
 {
-    gint x,y,w,h;
+    gint x,y,w;
     XftColor c;
     gint mw;
     PangoRectangle rect;
@@ -249,7 +249,7 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
     w = area->width;
     if (t->flow) w = MAX(w, t->maxwidth);
     w -= 4;
-    h = area->height;
+    /* h = area->height; */
 
     if (t->flow)
         ell = PANGO_ELLIPSIZE_NONE;
@@ -267,6 +267,8 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
         case RR_ELLIPSIZE_END:
             ell = PANGO_ELLIPSIZE_END;
             break;
+        default:
+            g_assert_not_reached();
         }
     }