Commit d6a2eedfddcded92c8f9b0ac022a99c4134696b0

Authored by André Goddard Rosa
Committed by Linus Torvalds
1 parent a11d2b64e1

lib/string.c: simplify strnstr()

Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Joe Perches <joe@perches.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 3 additions and 3 deletions Side-by-side Diff

... ... @@ -689,13 +689,13 @@
689 689 */
690 690 char *strnstr(const char *s1, const char *s2, size_t len)
691 691 {
692   - size_t l1 = len, l2;
  692 + size_t l2;
693 693  
694 694 l2 = strlen(s2);
695 695 if (!l2)
696 696 return (char *)s1;
697   - while (l1 >= l2) {
698   - l1--;
  697 + while (len >= l2) {
  698 + len--;
699 699 if (!memcmp(s1, s2, l2))
700 700 return (char *)s1;
701 701 s1++;