From: Sami Kerola Date: Fri, 12 Jul 2019 21:28:10 +0000 (+0100) Subject: include/xalloc: ensure xstrdup() and xstrndup() returns nonnull attribute X-Git-Tag: v2.35-rc1~317^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f3aded3fdb1e19818b05f205b74cd4bff7532811;p=thirdparty%2Futil-linux.git include/xalloc: ensure xstrdup() and xstrndup() returns nonnull attribute Turned out lsblk is passing null as argument to xstrdup(), so fix that and add assert() to make sure promise of not returning null is kept in future. Signed-off-by: Sami Kerola --- diff --git a/include/xalloc.h b/include/xalloc.h index 0129a85e2e..48712a4529 100644 --- a/include/xalloc.h +++ b/include/xalloc.h @@ -62,8 +62,7 @@ static inline char __attribute__((warn_unused_result)) __ul_returns_nonnull { char *ret; - if (!str) - return NULL; + assert(str); ret = strdup(str); @@ -77,8 +76,7 @@ xstrndup(const char *str, size_t size) { char *ret; - if (!str) - return NULL; + assert(str); ret = strndup(str, size); diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 3ce6da7302..7ab9dc23c2 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -774,8 +774,14 @@ static char *device_get_data( str = get_vfs_attribute(dev, id); break; case COL_TARGET: - str = xstrdup(lsblk_device_get_mountpoint(dev)); + { + char *s = lsblk_device_get_mountpoint(dev); + if (s) + str = xstrdup(s); + else + str = NULL; break; + } case COL_LABEL: prop = lsblk_device_get_properties(dev); if (prop && prop->label)