matrix-reader: Fix possibly-zero second argument to xcalloc().
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 20 Jun 2020 23:49:59 +0000 (23:49 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 20 Jun 2020 23:49:59 +0000 (23:49 +0000)
xcalloc() is documented to disallow zero for its second argument:

  /* Allocate zeroed memory for N elements of S bytes, with error
     checking.  S must be nonzero.  */
  void *
  xcalloc (size_t n, size_t s)

This code didn't always call it properly.

Found with AFL++.
Thanks to Andrea Fioraldi for reporting the problem.
Bug #58600.

src/language/data-io/matrix-reader.c

index 1dfe638882ced9bfc9f5335e58089be2967a54c2..6e73962a6acf1f19fd57c8bb040f3a3c815f9cab 100644 (file)
@@ -138,7 +138,7 @@ create_matrix_reader_from_case_reader (const struct dictionary *dict, struct cas
   if (vars)
     {
       int i;
-      *vars = xcalloc (sizeof (struct variable **), *n_vars);
+      *vars = xcalloc (*n_vars, sizeof (struct variable **));
 
       for (i = 0; i < *n_vars; ++i)
        {