]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: the last argument of sd_device_get_sysattr_value() may be NULL
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 18 Feb 2021 14:40:33 +0000 (23:40 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 20 Feb 2021 19:30:42 +0000 (04:30 +0900)
src/libsystemd/sd-device/sd-device.c

index 5e161ec03ffc6547b0b3175900b7dcaddad4b6a1..991779aa9c15766334aa4bdcbb5cf42e9c75e9f5 100644 (file)
@@ -1862,7 +1862,7 @@ static int device_get_cached_sysattr_value(sd_device *device, const char *_key,
 
 /* We cache all sysattr lookups. If an attribute does not exist, it is stored
  * with a NULL value in the cache, otherwise the returned string is stored */
-_public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **_value) {
+_public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **ret_value) {
         _cleanup_free_ char *value = NULL;
         const char *path, *syspath, *cached_value = NULL;
         struct stat statbuf;
@@ -1881,8 +1881,8 @@ _public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr,
                         /* we looked up the sysattr before and it did not exist */
                         return -ENOENT;
 
-                if (_value)
-                        *_value = cached_value;
+                if (ret_value)
+                        *ret_value = cached_value;
 
                 return 0;
         }
@@ -1929,7 +1929,8 @@ _public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr,
         if (r < 0)
                 return r;
 
-        *_value = TAKE_PTR(value);
+        if (ret_value)
+                *ret_value = TAKE_PTR(value);
 
         return 0;
 }