From: Zbigniew Jędrzejewski-Szmek Date: Fri, 17 Dec 2021 10:35:50 +0000 (+0100) Subject: udev/net_id: use STRLEN() to make code clearer X-Git-Tag: v250-rc3~22^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c1af24182dfe024ca236ff83118645183cd5e6a;p=thirdparty%2Fsystemd.git udev/net_id: use STRLEN() to make code clearer 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. --- diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index 4ca826b58e0..1b4330f6836 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -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; }