Fix: make sure there is enough ram available
This commit is contained in:
parent
81bcf3ea87
commit
ace85e64a0
4 changed files with 15 additions and 2 deletions
|
@ -1 +0,0 @@
|
||||||
|
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/sysinfo.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Open a file and load its stats
|
* @brief Open a file and load its stats
|
||||||
|
|
|
@ -33,7 +33,18 @@ uint8_t* read_file(const char* path, size_t* size) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct sysinfo info;
|
||||||
|
int r = sysinfo(&info);
|
||||||
|
if (r != 0 || info.freeram < (unsigned long)statOfFile.st_size * 2) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t* data = malloc(statOfFile.st_size);
|
uint8_t* data = malloc(statOfFile.st_size);
|
||||||
|
if (data == NULL) {
|
||||||
|
fclose(f);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
size_t bytesRead =
|
size_t bytesRead =
|
||||||
fread(data, statOfFile.st_blksize, statOfFile.st_blocks, f);
|
fread(data, statOfFile.st_blksize, statOfFile.st_blocks, f);
|
||||||
|
|
|
@ -138,8 +138,10 @@ int main(int argc, char** argv) {
|
||||||
char hash[32];
|
char hash[32];
|
||||||
if (!calculate_hash(c, hash)) {
|
if (!calculate_hash(c, hash)) {
|
||||||
if (errno != 0) {
|
if (errno != 0) {
|
||||||
fprintf(stderr, "\n\033[0;31mAn error occured: %s\033[0m\n",
|
fprintf(stderr, "\n\033[1;31mAn error occured: %s\033[0m\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
if (errno == ENOMEM)
|
||||||
|
fprintf(stderr, "\033[1;36mPlease try to use -V2!\033[0m\n");
|
||||||
}
|
}
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue