Fix: wrong filesize read
This commit is contained in:
parent
72e2136ceb
commit
1c42f4036f
2 changed files with 8 additions and 9 deletions
|
@ -36,9 +36,9 @@ md2: ${OBJ}
|
|||
t/%:
|
||||
@mkdir -p t
|
||||
@echo
|
||||
@echo "${BLUE}=== Generating ${subst t/,,$@}MB of random data... ===${NC}"
|
||||
@echo -e "${BLUE}=== Generating ${subst t/,,$@}MB of random data... ===${NC}"
|
||||
dd if=/dev/random of=$@ bs=1M count=${subst t/,,$@} status=progress
|
||||
@echo "${BLUE}=== done ===${NC}"
|
||||
@echo -e "${BLUE}=== done ===${NC}"
|
||||
@echo
|
||||
|
||||
benchmarks.csv: md2 ${TESTFILES}
|
||||
|
|
|
@ -35,22 +35,21 @@ uint8_t* read_file(const char* path, size_t* size) {
|
|||
|
||||
struct sysinfo info;
|
||||
int r = sysinfo(&info);
|
||||
if (r != 0 || info.freeram < (unsigned long)(statOfFile.st_blksize *
|
||||
statOfFile.st_blocks * 2)) {
|
||||
|
||||
if (r != 0 || info.freeram < (unsigned long)(statOfFile.st_size * 2)) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t* data = malloc(statOfFile.st_blksize * statOfFile.st_blocks);
|
||||
uint8_t* data = malloc(statOfFile.st_size);
|
||||
if (data == NULL) {
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t bytesRead =
|
||||
fread(data, statOfFile.st_blksize, statOfFile.st_blocks, f);
|
||||
// size_t bytesRead = fread(data, sizeof(uint8_t), statOfFile.st_size, f);
|
||||
if (bytesRead != 0 && !feof(f)) {
|
||||
fread(data, 1, statOfFile.st_size, f);
|
||||
|
||||
if (ferror(f)) {
|
||||
fclose(f);
|
||||
if (errno == 0) errno = EIO;
|
||||
return NULL;
|
||||
|
|
Loading…
Reference in a new issue