summaryrefslogtreecommitdiff
path: root/sirtet.c
diff options
context:
space:
mode:
Diffstat (limited to 'sirtet.c')
-rw-r--r--sirtet.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/sirtet.c b/sirtet.c
index 0a8cc8f..61427c1 100644
--- a/sirtet.c
+++ b/sirtet.c
@@ -7,6 +7,7 @@
#include <ncurses.h>
#include "pieces.h"
#include "ui.h"
+#include "util.h"
void clearmap(char** map, int mapH, int mapW) {
for (int r = 0; r < mapH; r++) {
@@ -23,6 +24,9 @@ int clearfull(char** map, int mapH, int mapW) {
// returns total number of blocks cleared
bool* rows_to_clear = malloc(mapH * sizeof(bool));
bool* cols_to_clear = malloc(mapW * sizeof(bool));
+ if (rows_to_clear == NULL || cols_to_clear == NULL)
+ mallocfail();
+
int rtc_count = 0;
int ctc_count = 0;
// scan all rows and columns
@@ -65,10 +69,18 @@ int clearfull(char** map, int mapH, int mapW) {
void sirtet(int H, int W, int P) {
// init memory and game state
char** map = malloc(H * sizeof(char*));
+ if (map == NULL)
+ mallocfail();
+
for (int r = 0; r < H; r++) {
map[r] = malloc(W * sizeof(char));
+ if (map[r] == NULL)
+ mallocfail();
}
struct piece** hand = malloc(P * sizeof(struct piece*));
+ if (hand == NULL)
+ mallocfail();
+
srand(time(NULL));
clearmap(map, H, W);
refillpieces(hand, P);