]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: minor optimization for sd_device_new_from_device_id()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 7 Mar 2021 06:24:15 +0000 (15:24 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 6 May 2021 12:51:08 +0000 (14:51 +0200)
(cherry picked from commit ff7a8d2938b24cb7ca7b69900395ecf837a43a23)

src/libsystemd/sd-device/sd-device.c

index bb4d453cee23fe3a492657cb31ccdf682620dc8c..da5fd2b73484b47772c516238bd26c2aa1adb028 100644 (file)
@@ -624,7 +624,7 @@ _public_ int sd_device_new_from_device_id(sd_device **ret, const char *id) {
                 struct ifreq ifr = {};
                 int ifindex;
 
-                r = ifr.ifr_ifindex = parse_ifindex(&id[1]);
+                r = ifr.ifr_ifindex = parse_ifindex(id + 1);
                 if (r < 0)
                         return r;
 
@@ -653,15 +653,14 @@ _public_ int sd_device_new_from_device_id(sd_device **ret, const char *id) {
         }
 
         case '+': {
-                char subsys[PATH_MAX];
-                char *sysname;
+                char subsys[NAME_MAX+1]; /* NAME_MAX does not include the trailing NUL. */
+                const char *sysname;
 
-                (void) strscpy(subsys, sizeof(subsys), id + 1);
-                sysname = strchr(subsys, ':');
+                sysname = strchr(id + 1, ':');
                 if (!sysname)
                         return -EINVAL;
 
-                sysname[0] = '\0';
+                (void) strnscpy(subsys, sizeof(subsys), id + 1, sysname - id - 1);
                 sysname++;
 
                 return sd_device_new_from_subsystem_sysname(ret, subsys, sysname);