From 308c3e15e29177e9321ad3b7c39a4ad9b2961dcb Mon Sep 17 00:00:00 2001 From: Caleb Sander Date: Wed, 30 Aug 2023 09:44:48 -0600 Subject: [PATCH] fabrics: only look for spaces in strchomp() strchomp() is only needed to strip trailing spaces from a string. There is no need to replace NUL characters with NUL characters. So simplify the check for "NUL or space" to just "space". Update the function description as well, as it doesn't strip all whitespace, just spaces. Signed-off-by: Caleb Sander --- src/nvme/fabrics.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c index 6e434e44..acbcda35 100644 --- a/src/nvme/fabrics.c +++ b/src/nvme/fabrics.c @@ -47,7 +47,7 @@ const char *nvmf_dev = "/dev/nvme-fabrics"; /** - * strchomp() - Strip trailing white space + * strchomp() - Strip trailing spaces * @str: String to strip * @max: Maximum length of string */ @@ -55,11 +55,8 @@ static void strchomp(char *str, int max) { int i; - for (i = max - 1; i >= 0; i--) { - if (str[i] != '\0' && str[i] != ' ') - return; - else - str[i] = '\0'; + for (i = max - 1; i >= 0 && str[i] == ' '; i--) { + str[i] = '\0'; } } -- 2.50.1