bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: memmem issues


From: Paul Eggert
Subject: Re: memmem issues
Date: Fri, 21 Dec 2007 14:05:57 -0800
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Eric Blake <address@hidden> writes:

> +  size_t *table = (size_t *) malloca (m * sizeof (size_t));
> +  if (table == NULL)
> +    return false;

Shouldn't this check for overflow in the multiplication?
Something like this, perhaps?

   size_t *table;
   if (xalloc_oversized (m, sizeof *table))
     return false;
   table = (size_t *) malloca (m * sizeof *table);
   if (table == NULL)
     return false;

> +     unsigned char b = (unsigned char) needle[i - 1];
> ...
> +         if (b == (unsigned char) needle[j])

Would it be cleaner to declare 'b' to be of type 'char' and avoid the
casts?

> +      if ((unsigned char) needle[j] == (unsigned char) *phaystack)

Can both casts be omitted?

> +    return memchr (haystack, (unsigned char) *Needle, haystack_len);

Can the cast be omitted?

> +    return (void *) haystack;

How about "return Haystack;"?  That avoids a cast.

(As you can tell, I prefer to avoid casts....)

> +  if (needle_len == 0)

Perhaps a __builtin_expect would be helpful here?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]