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/%:
|
t/%:
|
||||||
@mkdir -p t
|
@mkdir -p t
|
||||||
@echo
|
@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
|
dd if=/dev/random of=$@ bs=1M count=${subst t/,,$@} status=progress
|
||||||
@echo "${BLUE}=== done ===${NC}"
|
@echo -e "${BLUE}=== done ===${NC}"
|
||||||
@echo
|
@echo
|
||||||
|
|
||||||
benchmarks.csv: md2 ${TESTFILES}
|
benchmarks.csv: md2 ${TESTFILES}
|
||||||
|
|
|
@ -35,22 +35,21 @@ uint8_t* read_file(const char* path, size_t* size) {
|
||||||
|
|
||||||
struct sysinfo info;
|
struct sysinfo info;
|
||||||
int r = 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;
|
errno = ENOMEM;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* data = malloc(statOfFile.st_blksize * statOfFile.st_blocks);
|
uint8_t* data = malloc(statOfFile.st_size);
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytesRead =
|
fread(data, 1, statOfFile.st_size, f);
|
||||||
fread(data, statOfFile.st_blksize, statOfFile.st_blocks, f);
|
|
||||||
// size_t bytesRead = fread(data, sizeof(uint8_t), statOfFile.st_size, f);
|
if (ferror(f)) {
|
||||||
if (bytesRead != 0 && !feof(f)) {
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
if (errno == 0) errno = EIO;
|
if (errno == 0) errno = EIO;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in a new issue