From 15e093cae17cf57304b81cacbc59c741b5b1b0a2 Mon Sep 17 00:00:00 2001 From: Avril Date: Mon, 23 Nov 2020 15:09:04 +0000 Subject: [PATCH] fixed bad fread --- .gitignore | 3 ++- Makefile | 4 +++- src/main.c | 10 +++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 3192b9a..58b21ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *~ obj -build +build/ +test/ diff --git a/Makefile b/Makefile index b283fea..47fa08f 100644 --- a/Makefile +++ b/Makefile @@ -5,10 +5,12 @@ PROJECT=shuffle3 BUILD=build +OPT_FLAGS?= -march=native -fgraphite -fopenmp -floop-parallelize-all -ftree-parallelize-loops=4 + CFLAGS+= $(addprefix -I,$(INCLUDE)) -Wall -pedantic --std=gnu11 LDFLAGS+= -lm -RELEASE_CFLAGS?= -O3 -march=native -flto -fgraphite +RELEASE_CFLAGS?= -O3 -flto $(OPT_FLAGS) RELEASE_LDFLAGS?= -O3 -flto DEBUG_CFLAGS?= -g -O0 diff --git a/src/main.c b/src/main.c index 3ccc830..dfc3d24 100644 --- a/src/main.c +++ b/src/main.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -194,7 +195,14 @@ array_t read_whole_file(S_NAMED_LEXENV(base), FILE* fp) array_t ar; MANAGED({ void* buf = smalloc(sz); - fread(buf, 1, sz, fp); + + register size_t read; + register size_t full=0; + while ((read=fread(buf, 1, sz-full, fp))>0) + full+=read; + + assert(full == sz); + ar = ar_create_memory_from(base, buf, 1, sz); }); return ar;