diff --git a/Makefile b/Makefile index a16f2f8..137802f 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ NTHREADS= $(shell nproc) CC=gcc WARNINGS= -Wall DEBUG= -ggdb -fno-omit-frame-pointer -fdiagnostics-color=always -OPTIMIZE= -O2 +OPTIMIZE= -O3 INCLUDE= $(shell pkg-config --cflags glib-2.0 libxml-2.0 gtk4) LIBS= $(shell pkg-config --libs glib-2.0 libxml-2.0 gtk4) -lGL -lGLU -lm -lepoxy -lX11 -lGLEW @@ -121,6 +121,12 @@ run: build_system @$(BINDIR)/gem-graph-client @echo -e ${CL2}[$@] ${CL}done.${CL3} +debug: build_system + @echo -e ${CL2}[$@] ${CL}executing...${CL3} + @gdb $(BINDIR)/gem-graph-client + @echo -e ${CL2}[$@] ${CL}done.${CL3} + all: build_system @echo -e ${CL2}[$@] ${CL}done.${CL3} + diff --git a/include/base.h b/include/base.h index a05146e..c390fba 100644 --- a/include/base.h +++ b/include/base.h @@ -49,17 +49,19 @@ enum */ static inline bool read_file(char *filename, char **contents) { - int fd = open(filename, O_RDONLY); + int fd; + int filesize; + fd = open(filename, O_RDONLY); if(fd < 0) { printf("Couldn't read file: %s\n",filename); return false; } - int filesize = lseek(fd, 0, SEEK_END) +1 ; - *contents = malloc(sizeof(char) * filesize); + filesize = lseek(fd, 0, SEEK_END) +1 ; + *contents = calloc(filesize, sizeof(char)); - if (errno) { + if (contents == NULL) { perror("Not enough memory to allocate file"); return false; } @@ -67,7 +69,7 @@ static inline bool read_file(char *filename, char **contents) lseek(fd, 0, SEEK_SET); read(fd,*contents,filesize); - *contents[filesize-1]='\0'; + *(contents+filesize-1)='\0'; close(fd); diff --git a/manifest.scm b/manifest.scm index d77a78b..39b777c 100644 --- a/manifest.scm +++ b/manifest.scm @@ -10,6 +10,7 @@ "gcc-toolchain" "pkg-config" "findutils" + "gdb" "make" "gtk" "libxml2" diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index b35e4e6..ff0c9f1 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -46,7 +46,7 @@ /* * Dynamic array of ptr to dynamically allocated gl_area_entry */ -static struct gl_area_entry **gl_area_array = NULL; +struct gl_area_entry **gl_area_array = NULL; /* -------------------------------------------------------------------------- */ @@ -495,7 +495,8 @@ bool graphics_init(void *gl_area) gl_area_array = calloc(2, sizeof(struct gl_area_entry *)); // check if an error occured during allocation - if (errno) { + if (gl_area_array == NULL) { + printf("gl_area_array : %p", gl_area_array); perror("Not enough memory to allocate gl_area_array"); return false; } @@ -505,16 +506,19 @@ bool graphics_init(void *gl_area) gl_area_array = realloc(gl_area_array, (array_size + 1) * sizeof(struct gl_area_entry *)); - if (errno) { + if (gl_area_array == NULL) { perror("Not enough memory to allocate gl_area_array"); return false; } + + explicit_bzero(gl_area_array + array_size * sizeof(struct gl_area_entry *), + sizeof(struct gl_area_entry *)); } // Alloc new entry gl_area_array[array_size] = calloc(1, sizeof(struct gl_area_entry)); - if (errno) { + if (gl_area_array[array_size] == NULL) { perror("Not enough memory to allocate gl_area_array entry"); return false; }