Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #94 : Changed policy of choosing active buffer in struct ud #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions libudis86/syn.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ 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 = u->asm_buf_size - u->asm_buf_fill - 1 /* nullchar */;
ret = vsnprintf((char*) u->asm_buf + u->asm_buf_fill, avail, fmt, ap);

avail = 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 @@ -51,11 +51,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 @@ -71,7 +70,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 @@ -140,7 +142,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