aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2025-11-13 00:56:44 +0100
committerXavier Del Campo Romero <xavi92@disroot.org>2025-11-13 00:56:59 +0100
commit7fd2847cc5b45acbf8b6f0ca6608355f3fd277eb (patch)
treea263b6c8ce421bceec94e9404bfd5579804fbab2
parenta83684db1c1f24b9d744e7b6078e819bf44d169d (diff)
read_instr.c: Report offset on invalid instruction
This should help with troubleshooting.
-rw-r--r--read_instr.c14
1 files 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))