Prefer compiler warnings to assertions for unhandled switch cases
Using 'default:' cases can hide logical errors which would lead to i3 crashes for users. With this change the compiler will print a warning when a case is not handled. For example, if I add a new value in the Font.type enum: ../../i3/libi3/font.c: In function ‘draw_text’: ../../i3/libi3/font.c:378:5: warning: enumeration value ‘NEWFONT’ not handled in switch [-Wswitch] switch (savedFont->type) { ^~~~~~
This commit is contained in:
parent
393412a204
commit
0aa636b207
14
libi3/font.c
14
libi3/font.c
|
@ -283,9 +283,6 @@ void free_font(void) {
|
||||||
/* Free the font description */
|
/* Free the font description */
|
||||||
pango_font_description_free(savedFont->specific.pango_desc);
|
pango_font_description_free(savedFont->specific.pango_desc);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
savedFont = NULL;
|
savedFont = NULL;
|
||||||
|
@ -315,9 +312,6 @@ void set_font_colors(xcb_gcontext_t gc, color_t foreground, color_t background)
|
||||||
pango_font_green = foreground.green;
|
pango_font_green = foreground.green;
|
||||||
pango_font_blue = foreground.blue;
|
pango_font_blue = foreground.blue;
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,8 +382,6 @@ void draw_text(i3String *text, xcb_drawable_t drawable, xcb_gcontext_t gc,
|
||||||
draw_text_pango(i3string_as_utf8(text), i3string_get_num_bytes(text),
|
draw_text_pango(i3string_as_utf8(text), i3string_get_num_bytes(text),
|
||||||
drawable, visual, x, y, max_width, i3string_is_markup(text));
|
drawable, visual, x, y, max_width, i3string_is_markup(text));
|
||||||
return;
|
return;
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,8 +417,6 @@ void draw_text_ascii(const char *text, xcb_drawable_t drawable,
|
||||||
draw_text_pango(text, strlen(text),
|
draw_text_pango(text, strlen(text),
|
||||||
drawable, root_visual_type, x, y, max_width, false);
|
drawable, root_visual_type, x, y, max_width, false);
|
||||||
return;
|
return;
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,8 +509,6 @@ int predict_text_width(i3String *text) {
|
||||||
/* Calculate extents using Pango */
|
/* Calculate extents using Pango */
|
||||||
return predict_text_width_pango(i3string_as_utf8(text), i3string_get_num_bytes(text),
|
return predict_text_width_pango(i3string_as_utf8(text), i3string_get_num_bytes(text),
|
||||||
i3string_is_markup(text));
|
i3string_is_markup(text));
|
||||||
default:
|
}
|
||||||
assert(false);
|
assert(false);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,9 +44,6 @@ static bool tiling_resize_for_border(Con *con, border_t border, xcb_button_press
|
||||||
case BORDER_BOTTOM:
|
case BORDER_BOTTOM:
|
||||||
search_direction = D_DOWN;
|
search_direction = D_DOWN;
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool res = resize_find_tiling_participants(&first, &second, search_direction, false);
|
bool res = resize_find_tiling_participants(&first, &second, search_direction, false);
|
||||||
|
|
12
src/con.c
12
src/con.c
|
@ -1413,20 +1413,16 @@ orientation_t con_orientation(Con *con) {
|
||||||
return HORIZ;
|
return HORIZ;
|
||||||
|
|
||||||
case L_DEFAULT:
|
case L_DEFAULT:
|
||||||
DLOG("Someone called con_orientation() on a con with L_DEFAULT, this is a bug in the code.\n");
|
ELOG("Someone called con_orientation() on a con with L_DEFAULT, this is a bug in the code.\n");
|
||||||
assert(false);
|
assert(false);
|
||||||
return HORIZ;
|
|
||||||
|
|
||||||
case L_DOCKAREA:
|
case L_DOCKAREA:
|
||||||
case L_OUTPUT:
|
case L_OUTPUT:
|
||||||
DLOG("con_orientation() called on dockarea/output (%d) container %p\n", con->layout, con);
|
ELOG("con_orientation() called on dockarea/output (%d) container %p\n", con->layout, con);
|
||||||
assert(false);
|
|
||||||
return HORIZ;
|
|
||||||
|
|
||||||
default:
|
|
||||||
DLOG("con_orientation() ran into default\n");
|
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
/* should not be reached */
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -268,10 +268,6 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
|
||||||
case CT_DOCKAREA:
|
case CT_DOCKAREA:
|
||||||
ystr("dockarea");
|
ystr("dockarea");
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
DLOG("About to dump unknown container type=%d. This is a bug.\n", con->type);
|
|
||||||
assert(false);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* provided for backwards compatibility only. */
|
/* provided for backwards compatibility only. */
|
||||||
|
|
Loading…
Reference in New Issue