Skip to content

Commit 3c1af24

Browse files
committed
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.
1 parent be05866 commit 3c1af24

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/udev/udev-builtin-net_id.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,9 @@ static int names_vio(sd_device *dev, NetNames *names) {
491491
return 0;
492492
}
493493

494-
#define _PLATFORM_TEST "/sys/devices/platform/vvvvPPPP"
495-
#define _PLATFORM_PATTERN4 "/sys/devices/platform/%4s%4x:%2x/net/eth%u"
496-
#define _PLATFORM_PATTERN3 "/sys/devices/platform/%3s%4x:%2x/net/eth%u"
494+
#define PLATFORM_TEST "/sys/devices/platform/vvvvPPPP"
495+
#define PLATFORM_PATTERN4 "/sys/devices/platform/%4s%4x:%2x/net/eth%u"
496+
#define PLATFORM_PATTERN3 "/sys/devices/platform/%3s%4x:%2x/net/eth%u"
497497

498498
static int names_platform(sd_device *dev, NetNames *names, bool test) {
499499
sd_device *parent;
@@ -519,15 +519,15 @@ static int names_platform(sd_device *dev, NetNames *names, bool test) {
519519
return r;
520520

521521
/* syspath is too short, to have a valid ACPI instance */
522-
if (strlen(syspath) < sizeof _PLATFORM_TEST)
522+
if (strlen(syspath) < STRLEN(PLATFORM_TEST) + 1)
523523
return -EINVAL;
524524

525525
/* Vendor ID can be either PNP ID (3 chars A-Z) or ACPI ID (4 chars A-Z and numerals) */
526-
if (syspath[sizeof _PLATFORM_TEST - 1] == ':') {
527-
pattern = _PLATFORM_PATTERN4;
526+
if (syspath[STRLEN(PLATFORM_TEST)] == ':') {
527+
pattern = PLATFORM_PATTERN4;
528528
validchars = UPPERCASE_LETTERS DIGITS;
529529
} else {
530-
pattern = _PLATFORM_PATTERN3;
530+
pattern = PLATFORM_PATTERN3;
531531
validchars = UPPERCASE_LETTERS;
532532
}
533533

0 commit comments

Comments
 (0)