Read the json file into a dynamically-allocated array to avoid stack

overflow
This commit is contained in:
Abdelrahman Said 2023-07-02 20:55:31 +01:00
parent 09ed32e41a
commit 1bb16971b2

View File

@ -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) {