diff options
| author | 2022-10-21 16:00:35 -0700 | |
|---|---|---|
| committer | 2022-10-21 16:00:35 -0700 | |
| commit | 14e77332e74603efab8347c89d3cda447c3b97c9 (patch) | |
| tree | b7b8a48f4f75590266a763c52e072dda32b228ae /lib/string.c | |
| parent | lib: zstd: clean up double word in comment. (diff) | |
| parent | Merge tag 'for-linus-6.1-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip (diff) | |
| download | wireguard-linux-14e77332e74603efab8347c89d3cda447c3b97c9.tar.xz wireguard-linux-14e77332e74603efab8347c89d3cda447c3b97c9.zip | |
Merge branch 'main' into zstd-next
Diffstat (limited to 'lib/string.c')
| -rw-r--r-- | lib/string.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/lib/string.c b/lib/string.c index 485777c9da83..3371d26a0e39 100644 --- a/lib/string.c +++ b/lib/string.c @@ -197,6 +197,14 @@ ssize_t strscpy(char *dest, const char *src, size_t count) max = 0; #endif + /* + * read_word_at_a_time() below may read uninitialized bytes after the + * trailing zero and use them in comparisons. Disable this optimization + * under KMSAN to prevent false positive reports. + */ + if (IS_ENABLED(CONFIG_KMSAN)) + max = 0; + while (max >= sizeof(unsigned long)) { unsigned long c, data; @@ -517,21 +525,13 @@ EXPORT_SYMBOL(strnlen); size_t strspn(const char *s, const char *accept) { const char *p; - const char *a; - size_t count = 0; for (p = s; *p != '\0'; ++p) { - for (a = accept; *a != '\0'; ++a) { - if (*p == *a) - break; - } - if (*a == '\0') - return count; - ++count; + if (!strchr(accept, *p)) + break; } - return count; + return p - s; } - EXPORT_SYMBOL(strspn); #endif @@ -544,17 +544,12 @@ EXPORT_SYMBOL(strspn); size_t strcspn(const char *s, const char *reject) { const char *p; - const char *r; - size_t count = 0; for (p = s; *p != '\0'; ++p) { - for (r = reject; *r != '\0'; ++r) { - if (*p == *r) - return count; - } - ++count; + if (strchr(reject, *p)) + break; } - return count; + return p - s; } EXPORT_SYMBOL(strcspn); #endif |
