diff options
author | Benjamin Tissoires <benjamin.tissoires@redhat.com> | 2019-08-23 12:35:39 +0300 |
---|---|---|
committer | Benjamin Tissoires <benjamin.tissoires@redhat.com> | 2019-08-23 12:35:39 +0300 |
commit | 6f50fa2a6f1395ad5f59ce7b87730f1f3ea19d76 (patch) | |
tree | f826145c5bf9c502c033e7b67bcefc30eb0f9eee /lib/string.c | |
parent | 5b6cc1277a0536dae20f37d531f29b3416cee670 (diff) | |
parent | 15d90b242290f228166ea79ee1cc2db6b31a2143 (diff) | |
download | linux-6f50fa2a6f1395ad5f59ce7b87730f1f3ea19d76.tar.xz |
Merge branch 'master' into for-5.4/logitech
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Diffstat (limited to 'lib/string.c')
-rw-r--r-- | lib/string.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/string.c b/lib/string.c index 6016eb3ac73d..461fb620f85f 100644 --- a/lib/string.c +++ b/lib/string.c @@ -400,6 +400,9 @@ EXPORT_SYMBOL(strncmp); * strchr - Find the first occurrence of a character in a string * @s: The string to be searched * @c: The character to search for + * + * Note that the %NUL-terminator is considered part of the string, and can + * be searched for. */ char *strchr(const char *s, int c) { @@ -453,12 +456,18 @@ EXPORT_SYMBOL(strrchr); * @s: The string to be searched * @count: The number of characters to be searched * @c: The character to search for + * + * Note that the %NUL-terminator is considered part of the string, and can + * be searched for. */ char *strnchr(const char *s, size_t count, int c) { - for (; count-- && *s != '\0'; ++s) + while (count--) { if (*s == (char)c) return (char *)s; + if (*s++ == '\0') + break; + } return NULL; } EXPORT_SYMBOL(strnchr); |