Skip to content

Commit

Permalink
Fixed segmetation fault on graph
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyMich committed Nov 30, 2023
1 parent 2abbefa commit b4f25f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions main/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ OBJS = main.o $(MODULES)/Graph.o $(MODULES)/Node.o $(MODULES)/Neighbors.o $(MODU
EXEC = program

# Args for examples
ARGSEUCL = $(DATASETS)/00001000-4.bin 70 399 euclidean
ARGSEUCL = $(DATASETS)/00001000-4.bin 60 399 euclidean

ARGSMAN = $(DATASETS)/00001000-4.bin 70 399 manhattan
ARGSMAN = $(DATASETS)/00001000-4.bin 60 399 manhattan

$(EXEC): $(OBJS)
$(CC) $(OBJS) -o $(EXEC) $(LDFLAGS)
Expand Down
6 changes: 5 additions & 1 deletion modules/Graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ Graph* createGraphFromBinaryFile(String filename, int dimensions) {
Node** headNode = &graph->nodes;
int flag = 0; // Flag for feof

Dimension* headDimension = NULL;

// Read and process data from the binary file
while (!feof(file)) {

Dimension* headDimension = NULL;
headDimension = NULL;

for (int i = 0; i < dimensions; i++){
fread(&coordinate, sizeof(double), 1, file); // Read one double at a time
Expand All @@ -65,6 +67,8 @@ Graph* createGraphFromBinaryFile(String filename, int dimensions) {
}
}

freeDimensions(headDimension);

fclose(file);
return graph;
}
Expand Down

0 comments on commit b4f25f2

Please sign in to comment.