]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/unit: use assert for checking internal call sanity
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 8 Nov 2023 08:11:07 +0000 (09:11 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 13 Nov 2023 12:27:36 +0000 (13:27 +0100)
The only way this could be called with an invalid value would be if
somebody forgot to initialize unit type. In such cases, it's better to
fail hard immediately.

src/core/unit.c

index e865c393a3bf581cf50de6227cd2f57b68f3c6ca..66ac9c91ec0053fb8c2fb7fc265a8803e2c054df 100644 (file)
@@ -5079,10 +5079,7 @@ bool unit_type_supported(UnitType t) {
         static int8_t cache[_UNIT_TYPE_MAX] = {}; /* -1: disabled, 1: enabled: 0: don't know */
         int r;
 
-        if (_unlikely_(t < 0))
-                return false;
-        if (_unlikely_(t >= _UNIT_TYPE_MAX))
-                return false;
+        assert(t >= 0 && t < _UNIT_TYPE_MAX);
 
         if (cache[t] == 0) {
                 char *e;