Skip to content
Snippets Groups Projects
Commit c77ccef9 authored by rahix's avatar rahix
Browse files

Merge 'Fix config parser'

See merge request card10/firmware!291
parents 2a7e41fd 996e63ab
No related branches found
No related tags found
No related merge requests found
...@@ -270,17 +270,17 @@ void load_config(void) ...@@ -270,17 +270,17 @@ void load_config(void)
); );
return; return;
} }
char buf[CONFIG_MAX_LINE_LENGTH]; char buf[CONFIG_MAX_LINE_LENGTH + 1];
int lineNumber = 0; int lineNumber = 0;
int nread; int nread;
do { do {
//zero-terminate in case file is empty nread = epic_file_read(fd, buf, CONFIG_MAX_LINE_LENGTH);
buf[0] = '\0'; if (nread < CONFIG_MAX_LINE_LENGTH) {
nread = epic_file_read(fd, buf, sizeof(buf));
if (nread < sizeof(buf)) {
//add fake EOL to ensure termination //add fake EOL to ensure termination
buf[nread] = '\n'; buf[nread++] = '\n';
} }
//zero-terminate buffer
buf[nread] = '\0';
char *line = buf; char *line = buf;
char *eol = NULL; char *eol = NULL;
int last_eol = 0; int last_eol = 0;
...@@ -344,4 +344,5 @@ void load_config(void) ...@@ -344,4 +344,5 @@ void load_config(void)
} }
} }
} while (nread == sizeof(buf)); } while (nread == sizeof(buf));
epic_file_close(fd);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment