Bruno Haible <[EMAIL PROTECTED]> writes: > Most of your comments apply to all copies of the KMP code in gnulib.
Ouch! Should these be coalesced? >> Shouldn't this check for overflow in the multiplication? > > Yes, it should. I'm always lazy about this. OK, I installed this patch. 2007-12-29 Paul Eggert <[EMAIL PROTECTED]> * lib/memmem.c (knuth_morris_pratt): Check for size_t overflow when multiplying M by sizeof (size_t). diff --git a/lib/memmem.c b/lib/memmem.c index 58f95f7..b7f3e12 100644 --- a/lib/memmem.c +++ b/lib/memmem.c @@ -39,7 +39,10 @@ knuth_morris_pratt (const char *haystack, const char *last_haystack, const char **resultp) { /* Allocate the table. */ - size_t *table = (size_t *) malloca (m * sizeof (size_t)); + size_t *table; + if ((size_t) -1 / sizeof (size_t) < m) + return false; + table = (size_t *) malloca (m * sizeof (size_t)); if (table == NULL) return false; /* Fill the table.