Test MatrixFailsOnZeroDimensions

This commit is contained in:
engelpa103619 committed 2026-11-06 22:52:55 +01:00
1 parent 1720536667
commit 7e7bfbae3f
1 file changed
+6 -4
+6 -4
View File
@@ -7,15 +7,17 @@
Matrix createMatrix(unsigned int rows, unsigned int cols)
{
Matrix m;
m.rows = rows;
m.cols = cols;
if(rows == 0|| cols == 0) // Zeile oder Spalte = 0, dann keine Speicher anfordern, sonder Buffer auf NULL setzen
{
{
m.rows = 0;
m.cols = 0;
m.buffer = NULL;
return m;
}
m.rows = rows;
m.cols = cols;
m.buffer = (MatrixType*) calloc(rows * cols, sizeof(MatrixType)); // calloc, statt malloc benutzt, um direkt alle Werte mit 0 zu initialisieren
return m;
}