]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev/net_id: use STRLEN() to make code clearer
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 17 Dec 2021 10:35:50 +0000 (11:35 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 17 Dec 2021 10:45:55 +0000 (11:45 +0100)
The code was correct, but looked suspicious: we were comparing
strlen(x) with sizeof(y), with looks like an off-by-one. But we actually
want x to be one longer than y, so that's fine. Let's use STRLEN() to
make this more obvious.

While at it, drop unnecessary "_" prefix.

src/udev/udev-builtin-net_id.c

index 4ca826b58e0d9b223cc964a06934a50efdebd405..1b4330f6836cf59c86d285e851c49860c69d77b6 100644 (file)
@@ -491,9 +491,9 @@ static int names_vio(sd_device *dev, NetNames *names) {
         return 0;
 }
 
-#define _PLATFORM_TEST "/sys/devices/platform/vvvvPPPP"
-#define _PLATFORM_PATTERN4 "/sys/devices/platform/%4s%4x:%2x/net/eth%u"
-#define _PLATFORM_PATTERN3 "/sys/devices/platform/%3s%4x:%2x/net/eth%u"
+#define PLATFORM_TEST "/sys/devices/platform/vvvvPPPP"
+#define PLATFORM_PATTERN4 "/sys/devices/platform/%4s%4x:%2x/net/eth%u"
+#define PLATFORM_PATTERN3 "/sys/devices/platform/%3s%4x:%2x/net/eth%u"
 
 static int names_platform(sd_device *dev, NetNames *names, bool test) {
         sd_device *parent;
@@ -519,15 +519,15 @@ static int names_platform(sd_device *dev, NetNames *names, bool test) {
                 return r;
 
         /* syspath is too short, to have a valid ACPI instance */
-        if (strlen(syspath) < sizeof _PLATFORM_TEST)
+        if (strlen(syspath) < STRLEN(PLATFORM_TEST) + 1)
                 return -EINVAL;
 
         /* Vendor ID can be either PNP ID (3 chars A-Z) or ACPI ID (4 chars A-Z and numerals) */
-        if (syspath[sizeof _PLATFORM_TEST - 1] == ':') {
-                pattern = _PLATFORM_PATTERN4;
+        if (syspath[STRLEN(PLATFORM_TEST)] == ':') {
+                pattern = PLATFORM_PATTERN4;
                 validchars = UPPERCASE_LETTERS DIGITS;
         } else {
-                pattern = _PLATFORM_PATTERN3;
+                pattern = PLATFORM_PATTERN3;
                 validchars = UPPERCASE_LETTERS;
         }