Added null checks for malloc

This commit is contained in:
2025-03-30 22:24:56 +03:00
parent 0e992c3be5
commit 1dc0040fb3
5 changed files with 39 additions and 7 deletions

View File

@@ -1,6 +1,8 @@
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "utils.h"
extern boardInfo brdInfo;
@@ -37,3 +39,8 @@ int randomY(const clock_t initClock) {
void sleep_ms(const int ms) {
usleep(ms * 1000);
}
void mallocError(const char* varName, const char* fileName, const char* functionName) {
printf("Ran out of memory to allocate to %s in %s/%s\n", varName, fileName, functionName);
exit(1);
}

View File

@@ -2,6 +2,7 @@
#define UTILS_H_
#include <time.h>
#include "../globals.h"
extern boardInfo brdInfo;
@@ -10,5 +11,6 @@ int randomInt(const int start, const int end, const unsigned int seed);
int randomX(const clock_t initClock);
int randomY(const clock_t initClock);
void sleep_ms(const int ms);
void mallocError(const char* varName, const char* fileName, const char* functionName);
#endif // UTILS_H_