From 0b93e30c93efb243dafcdb7bde84fbf008df2135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 9 Aug 2023 19:55:42 +0200 Subject: [PATCH] libselinux: update string_to_mode() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drop parameter NULL check since the only caller does a NULL check on the argument. Avoid strlen(3) call by comparing by hand. Drop unreachable return statement. Signed-off-by: Christian Göttsche Acked-by: James Carter --- libselinux/src/label_file.h | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/libselinux/src/label_file.h b/libselinux/src/label_file.h index 190bc175..1363c83c 100644 --- a/libselinux/src/label_file.h +++ b/libselinux/src/label_file.h @@ -97,15 +97,10 @@ struct saved_data { struct selabel_sub *subs; }; -static inline mode_t string_to_mode(char *mode) +static inline mode_t string_to_mode(const char *mode) { - size_t len; - - if (!mode) - return 0; - len = strlen(mode); - if (mode[0] != '-' || len != 2) - return -1; + if (mode[0] != '-' || mode[1] == '\0' || mode[2] != '\0') + return (mode_t)-1; switch (mode[1]) { case 'b': return S_IFBLK; @@ -122,10 +117,8 @@ static inline mode_t string_to_mode(char *mode) case '-': return S_IFREG; default: - return -1; + return (mode_t)-1; } - /* impossible to get here */ - return 0; } static inline int grow_specs(struct saved_data *data)