🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.utils.bug
Article #106

Re: strstr broken in gdb-4.4/libiberty -- fix included

#106
From: Bruce Robert Larson
Date: Tue, 07 Apr 1992 09:01
95 lines
2521 bytes
I just sent in a bug report for strstr.c in gdb-4.4/libiberty.

After sending it, I discovered two things:
* I didn't update the external declaration of strcmp to strncmp
* the *patched* strstr doesn't return a pointer to the first string
  when the second string argument is NULL (it does not conform to
  the ANSI description).  

I'm including a new patch that solves both problems.

I'm also including a new version that I wrote that conforms
to the ANSI description and should be faster as well.  If you
decide to use my version, then please place it under the GNU
license.  The new version follows the corrected patch.


Bruce R Larson
blarson@ires.com
Integral Resources, Milton MA

--> first the corrected patch <--
*** ORIG/strstr.c       Mon Apr  6 21:12:57 1992
--- strstr.c    Tue Apr  7 03:53:15 1992
***************
*** 47,58 ****
    char *s1, *s2;
  {
    register char *p = s1 - 1;
    extern char *strchr ();
!   extern int strcmp ();

    while (0 != (p = strchr (p+1, *s2)))
      {
!       if (strcmp (p, s2))
        {
          return (p);
        }
--- 47,66 ----
    char *s1, *s2;
  {
    register char *p = s1 - 1;
+   register int len;
    extern char *strchr ();
!   extern int strncmp ();

+
+   if ( *s2 == '\0' )
+     return (s1);
+
+
+   len = strlen(s2);
+
    while (0 != (p = strchr (p+1, *s2)))
      {
!       if ( strncmp (p, s2, len) == 0 )
        {
          return (p);
        }


--> new version of strstr.c follows <--
/* strstr.c -- Bruce R Larson  April 7, 1992 */

# ifndef NULL
# define NULL 0
# endif

char *strstr(s1, s2)
    char *s1, *s2;
{
  register char c =*s2, *sp1, *sp2;


  if ( c == NULL )
    return s1;

  while(*s1)
    {
      if ( *s1 == c )
        {
          sp1 = s1; sp2 = s2;

          while( *sp2 != NULL && *sp1 == *sp2 )
            {
              sp1++; sp2++;
            }

          if ( *sp2 == NULL )
            return s1;
        }
      s1++;
    }

  return NULL;
}
Technical Details
Message-ID: <9204070901.AA12300@ra.cs.umb.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.umb.edu!blarson

Show Full Headers
Complete Article Headers
Newsgroups: gnu.utils.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.umb.edu!blarson
From: blarson@cs.umb.edu (Bruce Robert Larson)
Subject: Re: strstr broken in gdb-4.4/libiberty -- fix included
Message-ID: <9204070901.AA12300@ra.cs.umb.edu>
Sender: gnulists@ai.mit.edu
Reply-To: Bruce R Larson <blarson%ires.com@cs.umb.edu>
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 7 Apr 1992 09:01:23 GMT
Approved: bug-gnu-utils@prep.ai.mit.edu
Lines: 97