From: florian Date: Mon, 1 Mar 2021 15:56:00 +0000 (+0000) Subject: We really must handle all possible enumeration values in X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4b15555f05032b2b476611974f4a51507844874f;p=openbsd We really must handle all possible enumeration values in state_transition() and iface_timeout(). Let the compiler help us by emitting a warning when we missed one (-Wswitch). Reminded by jsg who pointed out that gcc is quite confused and thinks there is an out of bounds access in if_state_name[] in the default case. There is not, if_state_name[] and enum if_state have to be kept in sync. (Note that -Wswitch is not a silver bullet, it just happens to work here.) --- diff --git a/sbin/dhcpleased/engine.c b/sbin/dhcpleased/engine.c index 9329e9e05bf..e2dbd31c191 100644 --- a/sbin/dhcpleased/engine.c +++ b/sbin/dhcpleased/engine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: engine.c,v 1.4 2021/03/01 15:54:49 florian Exp $ */ +/* $OpenBSD: engine.c,v 1.5 2021/03/01 15:56:00 florian Exp $ */ /* * Copyright (c) 2017, 2021 Florian Obser @@ -1134,9 +1134,6 @@ state_transition(struct dhcpleased_iface *iface, enum if_state new_state) iface->timo.tv_sec /= 2; request_dhcp_request(iface); break; - default: - fatal("%s: unhandled state: %s", __func__, - if_state_name[new_state]); } log_debug("%s %s -> %s, timo: %lld", __func__, if_state_name[old_state], if_state_name[new_state], iface->timo.tv_sec); @@ -1198,8 +1195,6 @@ iface_timeout(int fd, short events, void *arg) else state_transition(iface, IF_REBINDING); break; - default: - break; } }