From: David Herrmann Date: Wed, 15 Jul 2015 10:30:08 +0000 (+0200) Subject: sd-device: never return NULL+0 X-Git-Tag: v226.4~1^2~209 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=f6035a5ec8045bf007c7ebc5ee5306418644e7aa;hp=ffd9a99e116775904762b688b2caabbc61e74c82 sd-device: never return NULL+0 It is highly confusing if a getter function returns 0, but the value is set to NULL. This, right now, triggers assertions as code relies on the returned values to be non-NULL. Like with sd-bus-creds and friends, return 0 only if a value is actually available. Discussed with Tom, and actually fixes real bugs as in #512. --- diff --git a/src/libelogind/sd-device/sd-device.c b/src/libelogind/sd-device/sd-device.c index b274f7109..7cea5a074 100644 --- a/src/libelogind/sd-device/sd-device.c +++ b/src/libelogind/sd-device/sd-device.c @@ -791,6 +791,9 @@ _public_ int sd_device_get_subsystem(sd_device *device, const char **ret) { device->subsystem_set = true; } + if (!device->subsystem) + return -ENOENT; + *ret = device->subsystem; return 0; @@ -908,6 +911,9 @@ _public_ int sd_device_get_driver(sd_device *device, const char **ret) { return log_debug_errno(r, "sd-device: could not set driver for %s: %m", device->devpath); } + if (!device->driver) + return -ENOENT; + *ret = device->driver; return 0; @@ -1002,6 +1008,8 @@ _public_ int sd_device_get_sysname(sd_device *device, const char **ret) { return r; } + assert_return(device->sysname, -ENOENT); + *ret = device->sysname; return 0;