MATRIX: Fix test for very large matrix.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 21 Oct 2024 17:49:00 +0000 (10:49 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 21 Oct 2024 17:49:00 +0000 (10:49 -0700)
I kept getting processes killed as out-of-memory for the "MATRIX - very
large matrices" test.  Somehow, GSL was really trying to allocate a
matrix with 230,000,000,000 elements, which would require 1.84 PB of
memory, which I don't have.

This makes the matrix allocator report out-of-memory if a sequence would
have more than about 2 billion elements, fixing my OOM killer problem.

src/language/commands/matrix.c

index acbef18df06dcb3c75d0fa39db891e07de08ae5d..8747992b10a64c05d9c8dbde93522737e7ea9eff 100644 (file)
@@ -3500,7 +3500,7 @@ matrix_expr_evaluate_seq (const struct matrix_expr *e,
   long int n = (end >= start && by > 0 ? (end - start + by) / by
                 : end <= start && by < 0 ? (start - end - by) / -by
                 : 0);
-  gsl_matrix *m = gsl_matrix_alloc (1, n);
+  gsl_matrix *m = n <= (long) INT32_MAX ? gsl_matrix_alloc (1, n) : NULL;
   if (m == NULL)
     {
       msg_at (SE, matrix_expr_location (e),