Thread View: gnu.utils.bug
1 messages
1 total messages
Started by Bruce Robert Larson
Tue, 07 Apr 1992 09:01
Re: strstr broken in gdb-4.4/libiberty -- fix included
Author: Bruce Robert Larson
Date: Tue, 07 Apr 1992 09:01
Date: Tue, 07 Apr 1992 09:01
95 lines
2521 bytes
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;
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads