This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bug in function memchr



The following listing is from gcc-2.95/libiberty/memchr.c

Search length data type is "size_t".  On HP-UX that data 
type is "unsigned int".

Test at line 53 will never fail when using "unsigned int length"

Suggest using "while ( length-- > 0 )"


     1	/*
     2	FUNCTION
     3		<<memchr>>---find character in memory
     4	
     5	INDEX
     6		memchr
     7	
     8	ANSI_SYNOPSIS
     9		#include <string.h>
    10		void *memchr(const void *<[src]>, int <[c]>, size_t
<[length]>);
    11	
    12	TRAD_SYNOPSIS
    13		#include <string.h>
    14		void *memchr(<[src]>, <[c]>, <[length]>)
    15		void *<[src]>;
    16		void *<[c]>;
    17		size_t <[length]>;
    18	
    19	DESCRIPTION
    20		This function searches memory starting at <<*<[src]>>> for
the
    21		character <[c]>.  The search only ends with the first
    22		occurrence of <[c]>, or after <[length]> characters; in
    23		particular, <<NULL>> does not terminate the search.
    24	
    25	RETURNS
    26		If the character <[c]> is found within <[length]> characters
    27		of <<*<[src]>>>, a pointer to the character is returned. If
    28		<[c]> is not found, then <<NULL>> is returned. 	
    29	
    30	PORTABILITY
    31	<<memchr>>  requires no supporting OS subroutines.
    32	
    33	QUICKREF
    34		memchr ansi pure
    35	
    36	*/
    37	
    38	#include <ansidecl.h>
    39	#ifdef __STDC__
    40	#include <stddef.h>
    41	#else
    42	#define size_t unsigned long
    43	#endif
    44	
    45	PTR
    46	memchr (src_void, c, length)
    47	     register const PTR src_void;
    48	     int c;
    49	     size_t length;
    50	{
    51	  const unsigned char *src = (const unsigned char *)src_void;
    52	  
    53	  while (--length >= 0)
    54	  {
    55	    if (*src == c)
    56	     return (PTR)src;
    57	    src++;
    58	  }
    59	  return NULL;
    60	}

----- END -----


Jim Potts

* phone: +01-713-982-6384
* mailto:james.potts@eds.com



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]