[Top][All Lists]
[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?
- memmem issues, Eric Blake, 2007/12/19
- Re: memmem issues, Jim Meyering, 2007/12/20
- Re: memmem issues, Jim Meyering, 2007/12/20
- Re: memmem issues, Simon Josefsson, 2007/12/20
- Re: memmem issues,
Paul Eggert <=
- Re: memmem issues, Paul Eggert, 2007/12/29
- Re: memmem issues, Bruno Haible, 2007/12/31
- Re: memmem issues, Paul Eggert, 2007/12/31
Re: memmem issues, Bruno Haible, 2007/12/26