* lib/memmem.c (knuth_morris_pratt): Check for size_t overflow
[pspp] / lib / memmem.c
index 58f95f73b1068873b0eb5b2db6af8519812257e8..b7f3e12c6cbba2989019250c9ad188a6685d8e36 100644 (file)
@@ -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.