It seems like if the brainfuck token does not exists,
the space allocated by the malloc will be lost forever (memory leak !)
BrainfuckInstruction * brainfuck_parse_character(char c) {
// put this AFTER the switch
BrainfuckInstruction *instruction = (BrainfuckInstruction *) malloc(sizeof(BrainfuckInstruction));
instruction->next = 0;
instruction->loop = 0;
instruction->difference = 1;
switch(c) {
case BRAINFUCK_TOKEN_PLUS:
case BRAINFUCK_TOKEN_MINUS:
case BRAINFUCK_TOKEN_NEXT:
case BRAINFUCK_TOKEN_PREVIOUS:
case BRAINFUCK_TOKEN_OUTPUT:
case BRAINFUCK_TOKEN_INPUT:
case BRAINFUCK_TOKEN_LOOP_START:
case BRAINFUCK_TOKEN_LOOP_END:
case BRAINFUCK_TOKEN_BREAK:
break;
default:
return NULL;
}
instruction->type = c;
return instruction;
}
It seems like if the brainfuck token does not exists,
the space allocated by the malloc will be lost forever (memory leak !)
BrainfuckInstruction * brainfuck_parse_character(char c) {
}