From 7fd2847cc5b45acbf8b6f0ca6608355f3fd277eb Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Thu, 13 Nov 2025 00:56:44 +0100 Subject: read_instr.c: Report offset on invalid instruction This should help with troubleshooting. --- read_instr.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/read_instr.c b/read_instr.c index 7f7d2a6..907069d 100644 --- a/read_instr.c +++ b/read_instr.c @@ -642,10 +642,16 @@ int read_instr(FILE *const f, struct parse *const p) for (;;) { - const size_t n = fread(&op, sizeof op, 1, f); + size_t n; varuint32 relative_depth; + const long offset = ftell(f); - if (!n) + if (offset < 0) + { + fprintf(stderr, "%s: ftell(3): %s\n", __func__, strerror(errno)); + goto failure; + } + else if (!(n = fread(&op, sizeof op, 1, f))) { fprintf(stderr, "%s: fread(3) failed, ferror(3)=%d, feof(3)=%d\n", __func__, ferror(f), feof(f)); @@ -653,8 +659,8 @@ int read_instr(FILE *const f, struct parse *const p) } else if (op >= sizeof table / sizeof *table || !table[op]) { - fprintf(stderr, "%s: invalid or unsupported opcode %#" PRIx8 "\n", - __func__, op); + fprintf(stderr, "%s: invalid or unsupported opcode %#" PRIx8 ", " + "offset=%#lx\n", __func__, op, offset); goto failure; } else if (table[op](f, &relative_depth)) -- cgit v1.2.3