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:
12
src/con.c
12
src/con.c
@ -1413,20 +1413,16 @@ orientation_t con_orientation(Con *con) {
|
||||
return HORIZ;
|
||||
|
||||
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);
|
||||
return HORIZ;
|
||||
|
||||
case L_DOCKAREA:
|
||||
case L_OUTPUT:
|
||||
DLOG("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");
|
||||
ELOG("con_orientation() called on dockarea/output (%d) container %p\n", con->layout, con);
|
||||
assert(false);
|
||||
}
|
||||
/* should not be reached */
|
||||
assert(false);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user