lsblk: fix null pointer dereferences

Both catched with -Wnull-dereference compiler option:

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2018-12-10 20:14:12 +00:00
parent 2859592ecb
commit e361253e88
No known key found for this signature in database
GPG Key ID: A9553245FDE9B739
2 changed files with 4 additions and 3 deletions

View File

@ -203,7 +203,8 @@ int lsblk_device_is_last_parent(struct lsblk_device *dev, struct lsblk_device *p
struct lsblk_devdep *dp = list_last_entry(
&dev->parents,
struct lsblk_devdep, ls_parents);
if (!dp)
return 0;
return dp->parent == parent;
}

View File

@ -747,7 +747,7 @@ static char *device_get_data(
case COL_OWNER:
{
struct stat *st = device_get_stat(dev);
struct passwd *pw = st ? NULL : getpwuid(st->st_uid);
struct passwd *pw = st ? getpwuid(st->st_uid) : NULL;
if (pw)
str = xstrdup(pw->pw_name);
break;
@ -755,7 +755,7 @@ static char *device_get_data(
case COL_GROUP:
{
struct stat *st = device_get_stat(dev);
struct group *gr = st ? NULL : getgrgid(st->st_gid);
struct group *gr = st ? getgrgid(st->st_gid) : NULL;
if (gr)
str = xstrdup(gr->gr_name);
break;