summaryrefslogtreecommitdiff
path: root/lib/string.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2019-09-14 18:24:57 +0300
committerTakashi Iwai <tiwai@suse.de>2019-09-14 18:26:10 +0300
commitd3f9990f1b48514b33342612b51fad238592d774 (patch)
tree9ad5ae81ba3e820e91a09e2675b7c98675bd809e /lib/string.c
parente1a00b5b253a4f97216b9a33199a863987075162 (diff)
parent7711fb7dac1ab77fd1b4d948f4647a569e4a1ae2 (diff)
downloadlinux-d3f9990f1b48514b33342612b51fad238592d774.tar.xz
Merge branch 'for-next' into for-linus
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'lib/string.c')
-rw-r--r--lib/string.c11
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);