From 1bb16971b2613a164690c195ad829abd601e6d47 Mon Sep 17 00:00:00 2001
From: Abdelrahman Said <said.abdelrahman89@gmail.com>
Date: Sun, 2 Jul 2023 20:55:31 +0100
Subject: [PATCH] Read the json file into a dynamically-allocated array to
 avoid stack overflow

---
 haversine_02/src/json/parser.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/haversine_02/src/json/parser.c b/haversine_02/src/json/parser.c
index 3ef9d87..98d0e43 100644
--- a/haversine_02/src/json/parser.c
+++ b/haversine_02/src/json/parser.c
@@ -33,7 +33,7 @@ jentity_t *load_json(const char *filepath) {
 
   fseek(fp, 0, SEEK_SET);
 
-  char json[length + 1];
+  char *json = (char *)malloc(sizeof(char) * (length + 1));
   memset(json, 0, length + 1);
 
   fread(json, sizeof(char), length, fp);
@@ -76,6 +76,7 @@ jentity_t *load_json(const char *filepath) {
 
   parser_free(&parser);
   lexer_free(&lexer);
+  free(json);
 
   return root;
 }
@@ -93,7 +94,7 @@ void parser_init(parser_t **parser) {
 
   (*parser)->root = NULL;
   (*parser)->current = NULL;
-  (*parser)->value = (jval_t){};
+  (*parser)->value = (jval_t){0};
 }
 
 void parser_free(parser_t **parser) {