From 05587cece54dd37a5290ac8143c28f837661769c Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 31 Mar 2025 18:20:22 +0200 Subject: [PATCH] xattr-util: add missing assertions Follow-up for ed024abac6e4acad5a77943721e7622bb1b10b71 and 9fbe26cfa8fadb58e048aa6a57ad0dacf5de03fc Also, let's not get too tangled up in the style of defining variables in between. The functions are short enough, and vars involved are still effectively at the beginning... Put differently, the separation from 'int r' is too deliberate and brings no actual value in my eyes. --- src/basic/xattr-util.c | 13 ++++++++----- src/basic/xattr-util.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c index f958e480ffb..deacc1025a6 100644 --- a/src/basic/xattr-util.c +++ b/src/basic/xattr-util.c @@ -192,10 +192,11 @@ int getxattr_at_bool(int fd, const char *path, const char *name, int at_flags) { } int getxattr_at_strv(int fd, const char *path, const char *name, int at_flags, char ***ret_strv) { + _cleanup_free_ char *nulstr = NULL; + size_t nulstr_size; int r; - _cleanup_free_ char *nulstr = NULL; - size_t nulstr_size = 0; + assert(ret_strv); r = getxattr_at_malloc(fd, path, name, at_flags, &nulstr, &nulstr_size); if (r < 0) @@ -343,11 +344,13 @@ int xsetxattr_full( return 0; } -int xsetxattr_strv(int fd, const char *path, int at_flags, const char *name, char * const* l) { +int xsetxattr_strv(int fd, const char *path, int at_flags, const char *name, char * const *l) { + _cleanup_free_ char *nulstr = NULL; + size_t size; int r; - _cleanup_free_ char *nulstr = NULL; - size_t size = 0; + assert(name); + r = strv_make_nulstr(l, &nulstr, &size); if (r < 0) return r; diff --git a/src/basic/xattr-util.h b/src/basic/xattr-util.h index 02293e50073..773e736cfb9 100644 --- a/src/basic/xattr-util.h +++ b/src/basic/xattr-util.h @@ -50,7 +50,7 @@ static inline int xsetxattr( return xsetxattr_full(fd, path, at_flags, name, value, SIZE_MAX, 0); } -int xsetxattr_strv(int fd, const char *path, int at_flags, const char *name, char *const*l); +int xsetxattr_strv(int fd, const char *path, int at_flags, const char *name, char * const *l); int xremovexattr(int fd, const char *path, int at_flags, const char *name); -- 2.47.3