lkml.org 
[lkml]   [2024]   [Apr]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] bpf: fix uninit-value in strnchr
Date
on Wed, 10 Apr 2024 08:28:01 +0800, Edward Adam Davis
> > * 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)
> lib/string.c
> 9 /**
> 8 * strnchr - Find a character in a length limited string
> 7 * @s: The string to be searched
> 6 * @count: The number of characters to be searched
> 5 * @c: The character to search for
> 4 *
> 3 * Note that the %NUL-terminator is considered part of the string, and can
> 2 * be searched for.
> 1 */
> 384 char *strnchr(const char *s, size_t count, int c)
> 1 {
> 2 while (count--) {
> 3 if (*s == (char)c) // Only when the length of s is 1, can NUL char be obtained
> 4 return (char *)s;
> 5 if (*s++ == '\0') // When the length of s is greater than 1, the loop will terminate and return NULL, without obtaining a pointer to a NUL char
> 6 break;
> 7 }
> 8 return NULL;
> 9 }
My comments is wrong, strnchr() work well.
> >
> >
> > > return -EINVAL;
> > > fmt_size = fmt_end - fmt;


\
 
 \ /
  Last update: 2024-04-11 14:20    [W:0.079 / U:1.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site