[xen staging] string: fix type use in strstr()

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[xen staging] string: fix type use in strstr()

patchbot
commit 3bf54c9dbf51bef4c48ef2fd2139e1c9a8c596d8
Author:     Jan Beulich <[hidden email]>
AuthorDate: Wed Mar 13 11:25:49 2019 +0100
Commit:     Jan Beulich <[hidden email]>
CommitDate: Wed Mar 13 11:25:49 2019 +0100

    string: fix type use in strstr()
   
    Using plain int for string lengths, while okay for all practical
    purposes, is undesirable in a generic library function.
   
    Take the opportunity and also move the function from being in the middle
    of mem*() ones to the set of str*() ones, convert its loop from while()
    to for(), and correct style.
   
    Signed-off-by: Jan Beulich <[hidden email]>
    Reviewed-by: Juergen Gross <[hidden email]>
    Acked-by: Andrew Cooper <[hidden email]>
---
 xen/common/string.c | 45 +++++++++++++++++++++------------------------
 1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/xen/common/string.c b/xen/common/string.c
index dafeaa827d..a2bbe7dc97 100644
--- a/xen/common/string.c
+++ b/xen/common/string.c
@@ -290,6 +290,27 @@ char * strsep(char **s, const char *ct)
 }
 #endif
 
+#ifndef __HAVE_ARCH_STRSTR
+/**
+ * strstr - Find the first substring in a %NUL terminated string
+ * @s1: The string to be searched
+ * @s2: The string to search for
+ */
+char *(strstr)(const char *s1, const char *s2)
+{
+ size_t l1, l2 = strlen(s2);
+
+ if (!l2)
+ return (char *)s1;
+
+ for (l1 = strlen(s1); l1 >= l2; --l1, ++s1)
+ if (!memcmp(s1, s2, l2))
+ return (char *)s1;
+
+ return NULL;
+}
+#endif
+
 #ifndef __HAVE_ARCH_MEMSET
 /**
  * memset - Fill a region of memory with the given value
@@ -380,30 +401,6 @@ int (memcmp)(const void *cs, const void *ct, size_t count)
 }
 #endif
 
-#ifndef __HAVE_ARCH_STRSTR
-/**
- * strstr - Find the first substring in a %NUL terminated string
- * @s1: The string to be searched
- * @s2: The string to search for
- */
-char *(strstr)(const char *s1, const char *s2)
-{
- int l1, l2;
-
- l2 = strlen(s2);
- if (!l2)
- return (char *) s1;
- l1 = strlen(s1);
- while (l1 >= l2) {
- l1--;
- if (!memcmp(s1,s2,l2))
- return (char *) s1;
- s1++;
- }
- return NULL;
-}
-#endif
-
 #ifndef __HAVE_ARCH_MEMCHR
 /**
  * memchr - Find a character in an area of memory.
--
generated by git-patchbot for /home/xen/git/xen.git#staging

_______________________________________________
Xen-changelog mailing list
[hidden email]
https://lists.xenproject.org/xen-changelog