Technically, arithmetic on null pointers is undefined behavior,
even if only adding zero. This may happen inside
isl_mat_left_hermite if the number of columns is zero.
Simply skip the entire computation in that case.
Signed-off-by: Michael Kruse <isl@meinersbur.de>
Signed-off-by: Sven Verdoolaege <sven.verdoolaege@gmail.com>
@@ -650,9 +650,6 @@ __isl_give isl_mat *isl_mat_left_hermite(__isl_take isl_mat *M, int neg,
*Q = NULL;
if (!M)
goto error;
- M = isl_mat_cow(M);
- if (!M)
- goto error;
if (U) {
*U = isl_mat_identity(M->ctx, M->n_col);
if (!*U)
@@ -664,6 +661,13 @@ __isl_give isl_mat *isl_mat_left_hermite(__isl_take isl_mat *M, int neg,
goto error;
}
+ if (M->n_col == 0)
+ return M;
+
+ M = isl_mat_cow(M);
+ if (!M)
+ goto error;
+
col = 0;
isl_int_init(c);
for (row = 0; row < M->n_row; ++row) {