public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libiberty: Make strstr.c in libiberty ANSI compliant
@ 2020-05-02  0:06 Seija Kijin
  2020-11-13 18:53 ` Jeff Law
  0 siblings, 1 reply; 4+ messages in thread
From: Seija Kijin @ 2020-05-02  0:06 UTC (permalink / raw)
  To: gcc-patches

The original code in libiberty says "FIXME" and then says it has not been
validated to be ANSI compliant. However, this patch changes the function to
match implementations that ARE compliant, and such code is in the public
domain.

I ran the test results, and there are no test failures.

--- strstr.c 2020-03-12 07:07:24.000000000 -0400
+++ strstr_fixed.c 2020-05-01 19:53:13.904340902 -0400
@@ -16,26 +16,20 @@

 */

-
-/* FIXME:  The above description is ANSI compiliant.  This routine has not
-   been validated to comply with it.  -fnf */
-
 #include <stddef.h>

-extern char *strchr (const char *, int);
-extern int strncmp (const void *, const void *, size_t);
+extern int memcmp (const void *, const void *, size_t);
 extern size_t strlen (const char *);

 char *
 strstr (const char *s1, const char *s2)
 {
-  const char *p = s1;
   const size_t len = strlen (s2);
-
-  for (; (p = strchr (p, *s2)) != 0; p++)
-    {
-      if (strncmp (p, s2, len) == 0)
- return (char *)p;
-    }
+  while (*s1)
+  {
+    if (!memcmp (s1, s2, len))
+      return (char *)s1;
+    ++s1;
+  }
   return (0);
 }

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-04-02 17:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-02  0:06 [PATCH] libiberty: Make strstr.c in libiberty ANSI compliant Seija Kijin
2020-11-13 18:53 ` Jeff Law
2023-03-29 15:00   ` Jakub Jelinek
2023-04-02 17:54     ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).