Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixes vmt#94 in the original udis86 project (also refer to PR vmt#96).

Merge remote-tracking branch 'hasherezade/fix-94'
  • Loading branch information
canihavesomecoffee committed Jan 14, 2021
2 parents d795a2b + e51a647 commit 28f8cb1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
9 changes: 6 additions & 3 deletions libudis86/syn.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,14 @@ ud_asmprintf(struct ud *u, const char *fmt, ...)
int ret;
int avail;
va_list ap;
char* curr_buf = (u->asm_buf == NULL) ? u->asm_buf_int : u->asm_buf;
size_t curr_buf_size = (curr_buf == u->asm_buf_int) ? sizeof(u->asm_buf_int) : u->asm_buf_size;

va_start(ap, fmt);
avail = (int) (u->asm_buf_size - u->asm_buf_fill - 1) /* nullchar */;
ret = vsnprintf((char*) u->asm_buf + u->asm_buf_fill, avail, fmt, ap);
avail = (int) (curr_buf_size - u->asm_buf_fill - 1) /* nullchar */;
ret = vsnprintf((char*) curr_buf + u->asm_buf_fill, avail, fmt, ap);
if (ret < 0 || ret > avail) {
u->asm_buf_fill = u->asm_buf_size - 1;
u->asm_buf_fill = curr_buf_size - 1;
} else {
u->asm_buf_fill += ret;
}
Expand Down
15 changes: 10 additions & 5 deletions libudis86/udis86.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ ud_init(struct ud* u)
#ifndef __UD_STANDALONE__
ud_set_input_file(u, stdin);
#endif /* __UD_STANDALONE__ */

ud_set_asm_buffer(u, u->asm_buf_int, sizeof(u->asm_buf_int));
u->asm_buf = NULL;
u->asm_buf_size = 0;
}


/* =============================================================================
* ud_disassemble
* Disassembles one instruction and returns the number of
Expand All @@ -72,7 +71,10 @@ ud_disassemble(struct ud* u)
}
if ((len = ud_decode(u)) > 0) {
if (u->translator != NULL) {
u->asm_buf[0] = '\0';
u->asm_buf_int[0] = '\0';
if (u->asm_buf && u->asm_buf_size > 0) {
u->asm_buf[0] = '\0';
}
u->translator(u);
}
}
Expand Down Expand Up @@ -141,7 +143,10 @@ ud_set_syntax(struct ud* u, void (*t)(struct ud*))
const char*
ud_insn_asm(const struct ud* u)
{
return u->asm_buf;
if (u->asm_buf != NULL) {
return u->asm_buf;
}
return u->asm_buf_int;
}

/* =============================================================================
Expand Down

0 comments on commit 28f8cb1

Please sign in to comment.