# HG changeset patch # User Michael Pavone # Date 1660496106 25200 # Node ID 935e684f2d58990b519404604682e6bc451e3b3f # Parent 3d2cc2af1da3fa5b26404097fa5daacc53a16d31 Fix crash bug in expression parser diff -r 3d2cc2af1da3 -r 935e684f2d58 debug.c --- 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);