From 9dd4eff0d7f17012f14679605cb9e53e3dd7d053 Mon Sep 17 00:00:00 2001 From: Giorgi Kesidis Date: Mon, 10 Nov 2025 20:07:53 +0100 Subject: [PATCH] Bug-Fix create matrix --- matrix.c | 11 +++++++++++ matrix.h | 1 + 2 files changed, 12 insertions(+) diff --git a/matrix.c b/matrix.c index f67e8e7..d47c550 100644 --- a/matrix.c +++ b/matrix.c @@ -8,6 +8,16 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) { Matrix matrix; + + if(rows == 0 || cols == 0) + { + matrix.rows = 0; + matrix.cols = 0; + matrix.data = NULL; + return matrix; + } + + matrix.rows = rows; matrix.cols = cols; @@ -29,6 +39,7 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) matrix.data[i * matrix.cols + j] = UNDEFINED_MATRIX_VALUE; } } + return matrix; } void clearMatrix(Matrix *matrix) diff --git a/matrix.h b/matrix.h index e10b794..3772325 100644 --- a/matrix.h +++ b/matrix.h @@ -11,6 +11,7 @@ typedef struct Matrix { unsigned int rows; unsigned int cols; MatrixType *data; + #define buffer data } Matrix;