Mercurial > repos > blastem
changeset 2186:935e684f2d58
Fix crash bug in expression parser
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 14 Aug 2022 09:55:06 -0700 |
parents | 3d2cc2af1da3 |
children | d0129f19ca52 |
files | debug.c |
diffstat | 1 files changed, 20 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/debug.c Sat Aug 13 23:24:54 2022 -0700 +++ b/debug.c Sun Aug 14 09:55:06 2022 -0700 @@ -184,7 +184,7 @@ if (done) { break; } - + ++*end; } char *name = malloc(*end - start + 1); @@ -555,14 +555,29 @@ case '|': case '^': bin->right = parse_scalar(after_second, end); + if (!bin->right) { + fprintf(stderr, "Expected expression to the right of %s\n", second.v.op); + free_expr(bin); + return NULL; + } return maybe_binary(bin, *end, end); case '+': case '-': bin->right = parse_scalar_or_muldiv(after_second, end); + if (!bin->right) { + fprintf(stderr, "Expected expression to the right of %s\n", second.v.op); + free_expr(bin); + return NULL; + } return maybe_binary(bin, *end, end); case '=': case '!': bin->right = parse_expression(after_second, end); + if (!bin->right) { + fprintf(stderr, "Expected expression to the right of %s\n", second.v.op); + free_expr(bin); + return NULL; + } return bin; default: fprintf(stderr, "%s is not a valid binary operator\n", second.v.op); @@ -946,7 +961,7 @@ } out->def = def; out->format = format; - + ret = 1; cleanup_args: if (!ret) { @@ -1588,7 +1603,7 @@ } m68k_context *m68k = root->cpu_context; segacd_context *cd = m68k->system; - + if (param && *param && !isspace(*param)) { parsed_command cmd; debug_root *main_root = find_m68k_root(cd->genesis->m68k); @@ -1616,7 +1631,7 @@ } m68k_context *m68k = root->cpu_context; genesis_context *gen = m68k->system; - + if (param && *param && !isspace(*param)) { parsed_command cmd; debug_root *z80_root = find_z80_root(gen->z80); @@ -2085,7 +2100,7 @@ ++param; } genesis_context *gen = (genesis_context *)current_system; - + if (param && *param && !isspace(*param)) { parsed_command cmd; debug_root *m68k_root = find_m68k_root(gen->m68k);