summaryrefslogtreecommitdiff
path: root/ndisasm.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-12-20 12:24:17 -0800
committerH. Peter Anvin <hpa@zytor.com>2007-12-20 12:24:17 -0800
commit914fdf9ba0e4b4b21eda5b0b191c2cad3aaf19e0 (patch)
treed3ad4c80a51fd0d29ab794dd647eed3efae9999f /ndisasm.c
parenta81c62e18f20f4876f7ae96eee9aaf3d3268f4e7 (diff)
downloadnasm-914fdf9ba0e4b4b21eda5b0b191c2cad3aaf19e0.tar.gz
nasm-914fdf9ba0e4b4b21eda5b0b191c2cad3aaf19e0.tar.bz2
nasm-914fdf9ba0e4b4b21eda5b0b191c2cad3aaf19e0.zip
ndisasm: handle instructions at offset zero
Correctly handle instructions at offset zero
Diffstat (limited to 'ndisasm.c')
-rw-r--r--ndisasm.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/ndisasm.c b/ndisasm.c
index 479bfe4..a5ca292 100644
--- a/ndisasm.c
+++ b/ndisasm.c
@@ -259,7 +259,8 @@ int main(int argc, char **argv)
nextsync = next_sync(offset, &synclen);
do {
uint32_t to_read = buffer + sizeof(buffer) - p;
- if (nextsync && to_read > nextsync - offset - (p - q))
+ if ((nextsync || synclen) &&
+ to_read > nextsync - offset - (p - q))
to_read = nextsync - offset - (p - q);
if (to_read) {
lenread = fread(p, 1, to_read, fp);
@@ -268,7 +269,8 @@ int main(int argc, char **argv)
} else
lenread = 0;
p += lenread;
- if (nextsync && (uint32_t)offset == nextsync) {
+ if ((nextsync || synclen) &&
+ (uint32_t)offset == nextsync) {
if (synclen) {
fprintf(stdout, "%08"PRIX32" skipping 0x%"PRIX32" bytes\n", offset, synclen);
offset += synclen;
@@ -282,7 +284,8 @@ int main(int argc, char **argv)
disasm((uint8_t *) q, outbuf, sizeof(outbuf), bits, offset, autosync,
prefer);
if (!lendis || lendis > (p - q)
- || (uint32_t)lendis > nextsync - offset)
+ || ((nextsync || synclen) &&
+ (uint32_t)lendis > nextsync - offset))
lendis = eatbyte((uint8_t *) q, outbuf, sizeof(outbuf));
output_ins(offset, (uint8_t *) q, lendis, outbuf);
q += lendis;