Skip to content
Snippets Groups Projects
Commit 1d4125fc authored by JasonJPu's avatar JasonJPu
Browse files

Fix off by one strcpy

parent 72780f3c
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -5,6 +5,7 @@
#include "parser.h"
cons_cell* parse(char* input, int size) {
printf("%s\n", input);
if (input[0] == NULL) {
assert(size == 0);
return NULL;
......@@ -22,12 +23,12 @@ cons_cell* parse(char* input, int size) {
next_char++;
}
char buffer_next[500];
strncpy(buffer_next, &input[next_char], size - next_char);
cons_cell* cdr_cons = parse(buffer_next, size - next_char);
strncpy(buffer_next, &input[next_char], size - next_char + 1);
cons_cell* cdr_cons = parse(buffer_next, size - next_char + 1);
return create_cons_cell(car_cons, cdr_cons);
} else {
int first_space_idx = 0;
while (input[first_space_idx] != " " && input[first_space_idx] != NULL)
while (input[first_space_idx] != ' ' && input[first_space_idx] != NULL)
first_space_idx++;
char buff_first[500];
......@@ -39,8 +40,8 @@ cons_cell* parse(char* input, int size) {
next_char++;
}
strncpy(buff_other, &input[next_char], size - next_char);
cons_cell* cdr_cons = parse(buff_other, size-next_char);
strncpy(buff_other, &input[next_char], size - next_char + 1);
cons_cell* cdr_cons = parse(buff_other, size - next_char + 1);
car_cons->cdr = cdr_cons;
return car_cons;
}
......
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