diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-03-07 07:24:15 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-04-30 12:21:18 +0200 |
commit | ff7a8d2938b24cb7ca7b69900395ecf837a43a23 (patch) | |
tree | 1a86ce822a821242fe79de47a0db97124ed82859 /src/libsystemd | |
parent | sd-device: check the validity of device id (diff) | |
download | systemd-ff7a8d2938b24cb7ca7b69900395ecf837a43a23.tar.xz systemd-ff7a8d2938b24cb7ca7b69900395ecf837a43a23.zip |
sd-device: minor optimization for sd_device_new_from_device_id()
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 233bb6df5d..fbb5debff4 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -623,7 +623,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; @@ -652,15 +652,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); |