feat: return nullchecks updated

This commit is contained in:
finn 2022-07-20 09:21:48 +02:00
parent fda4ee592d
commit e516595eb2
4 changed files with 8 additions and 8 deletions

View file

@ -36,7 +36,7 @@ uint8_t* read_file(const char* path, size_t* size) {
uint8_t* data = malloc(statOfFile.st_size); uint8_t* data = malloc(statOfFile.st_size);
if (data == NULL) { if (data == NULL) {
printf("Failure: malloc returns NULL"); printf("Failure: malloc returns NULL");
return -1; return EXIT_FAILURE;
} }
size_t bytesRead = size_t bytesRead =

View file

@ -27,7 +27,7 @@ void md2_hash_0(size_t len, const uint8_t buf[len], uint8_t out[16]) {
uint8_t* newBuf = calloc(len + 16, sizeof(uint8_t)); uint8_t* newBuf = calloc(len + 16, sizeof(uint8_t));
if (newBuf == NULL) { if (newBuf == NULL) {
printf("Failure: calloc returns NULL"); printf("Failure: calloc returns NULL");
return -1; return EXIT_FAILURE;
} }
memcpy(newBuf, buf, len - paddingNeeded); memcpy(newBuf, buf, len - paddingNeeded);
@ -50,7 +50,7 @@ void md2_hash_0(size_t len, const uint8_t buf[len], uint8_t out[16]) {
uint8_t* messageDigestBuf = calloc(48, sizeof(uint8_t)); uint8_t* messageDigestBuf = calloc(48, sizeof(uint8_t));
if (messageDigestBuf == NULL) { if (messageDigestBuf == NULL) {
printf("Failure: calloc returns NULL"); printf("Failure: calloc returns NULL");
return -1; return EXIT_FAILURE;
} }

View file

@ -48,7 +48,7 @@ void md2_hash_1(size_t len, const uint8_t buf[len], uint8_t out[16])
uint8_t* newBuf = aligned_alloc(16, sizeof(uint8_t)*(len + 16)); uint8_t* newBuf = aligned_alloc(16, sizeof(uint8_t)*(len + 16));
if (newBuf == NULL) { if (newBuf == NULL) {
printf("Failure: aligned_alloc returns NULL"); printf("Failure: aligned_alloc returns NULL");
return -1; return EXIT_FAILURE;
} }
for(size_t i = 0; i < 16; i++) { for(size_t i = 0; i < 16; i++) {
@ -66,7 +66,7 @@ void md2_hash_1(size_t len, const uint8_t buf[len], uint8_t out[16])
uint8_t *messageDigestBuf = aligned_alloc(16, sizeof(uint8_t) * 48); uint8_t *messageDigestBuf = aligned_alloc(16, sizeof(uint8_t) * 48);
if (messageDigestBuf == NULL) { if (messageDigestBuf == NULL) {
printf("Failure: aligned_alloc returns NULL"); printf("Failure: aligned_alloc returns NULL");
return -1; return EXIT_FAILURE;
} }
for (size_t i = 0; i < 48; i++) { for (size_t i = 0; i < 48; i++) {

View file

@ -52,7 +52,7 @@ void md2_hash_2(size_t len, const uint8_t buf[len], uint8_t out[16]) {
uint8_t* messageDigestBuf = calloc(48, sizeof(uint8_t)); uint8_t* messageDigestBuf = calloc(48, sizeof(uint8_t));
if (messageDigestBuf == NULL) { if (messageDigestBuf == NULL) {
printf("Failure: calloc returns NULL"); printf("Failure: calloc returns NULL");
return -1; return EXIT_FAILURE;
} }
// === step 4 === // === step 4 ===
@ -60,13 +60,13 @@ void md2_hash_2(size_t len, const uint8_t buf[len], uint8_t out[16]) {
uint8_t* checksum = calloc(16, sizeof(uint8_t)); uint8_t* checksum = calloc(16, sizeof(uint8_t));
if (checksum == NULL) { if (checksum == NULL) {
printf("Failure: calloc returns NULL"); printf("Failure: calloc returns NULL");
return -1; return EXIT_FAILURE;
} }
uint8_t* data = malloc(16); uint8_t* data = malloc(16);
if (data == NULL) { if (data == NULL) {
printf("Failure: malloc returns NULL"); printf("Failure: malloc returns NULL");
return -1; return EXIT_FAILURE;
} }
size_t bytes_left_to_read = file_stat.st_size; size_t bytes_left_to_read = file_stat.st_size;
size_t bytes_left_to_process = 0; size_t bytes_left_to_process = 0;