]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
fabrics: only look for spaces in strchomp()
authorCaleb Sander <csander@purestorage.com>
Wed, 30 Aug 2023 15:44:48 +0000 (09:44 -0600)
committerDaniel Wagner <wagi@monom.org>
Mon, 4 Sep 2023 17:23:24 +0000 (19:23 +0200)
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 <csander@purestorage.com>
src/nvme/fabrics.c

index 6e434e44525f60744dafc1fb0852ede609f173ce..acbcda35c5902ba7f2d8f5283a8d308b7dafa38e 100644 (file)
@@ -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';
        }
 }