Handle NULL result from read_expression() in REPL
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "repl.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void init_repl(repl_t *repl)
|
||||
{
|
||||
@@ -19,6 +20,12 @@ bool step_repl(repl_t *repl)
|
||||
repl->line_buffer[len] = (char)byte;
|
||||
}
|
||||
const expression_t *e = repl->read(&repl->pool, repl->line_buffer, len);
|
||||
if (NULL == e) {
|
||||
const char *msg = "Invalid expression\n";
|
||||
repl->print(msg, strlen(msg));
|
||||
return true;
|
||||
}
|
||||
|
||||
const int result = repl->evaluate(e);
|
||||
const int result_len = snprintf(
|
||||
repl->result_buffer, REPL_RESULT_BUFFER_SIZE, "%d\n", result);
|
||||
|
||||
Reference in New Issue
Block a user