We really must handle all possible enumeration values in
authorflorian <florian@openbsd.org>
Mon, 1 Mar 2021 15:56:00 +0000 (15:56 +0000)
committerflorian <florian@openbsd.org>
Mon, 1 Mar 2021 15:56:00 +0000 (15:56 +0000)
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.)

sbin/dhcpleased/engine.c

index 9329e9e..e2dbd31 100644 (file)
@@ -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 <florian@openbsd.org>
@@ -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;
        }
 }