From 07724ab645593b5aa6d9ba0cf35aad4af29080ab Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 15 Feb 2021 11:41:08 -0500 Subject: [PATCH] Fix an off by one in strnlena() I wrote a test case for strnlena() and strndupa() and of course both were off by one in the opposite directions... ... but the next patch obviates the need for them, hopefully, so this will wind up getting dropped. --- include/str.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/str.h b/include/str.h index eee8336..14089c7 100644 --- a/include/str.h +++ b/include/str.h @@ -3,12 +3,11 @@ #ifndef SHIM_STR_H #define SHIM_STR_H -static inline -__attribute__((unused)) -unsigned long strnlena(const CHAR8 *s, unsigned long n) +static inline __attribute__((unused)) unsigned long +strnlena(const CHAR8 *s, unsigned long n) { unsigned long i; - for (i = 0; i <= n; i++) + for (i = 0; i < n; i++) if (s[i] == '\0') break; return i;