Added null checks for malloc
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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_
|
||||
|
||||
Reference in New Issue
Block a user