Skip to content

Commit

Permalink
replace offset_of with offsetof from stddef.h
Browse files Browse the repository at this point in the history
  • Loading branch information
aquynh committed Jun 17, 2014
1 parent 4fe5995 commit cae09bf
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion arch/PowerPC/PPCDisassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ static DecodeStatus getInstruction(MCInst *MI,
(code[1] << 8) | (code[0] << 0);

if (MI->flat_insn->detail) {
memset(&MI->flat_insn->detail->ppc, 0, offset_of(cs_ppc, operands));
memset(&MI->flat_insn->detail->ppc, 0, offsetof(cs_ppc, operands));
}

result = decodeInstruction_4(DecoderTable32, MI, insn, Address, 4);
Expand Down
2 changes: 1 addition & 1 deletion arch/Sparc/SparcDisassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ bool Sparc_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst *
return MCDisassembler_Fail;

if (MI->flat_insn->detail) {
memset(&MI->flat_insn->detail->sparc, 0, offset_of(cs_sparc, operands));
memset(&MI->flat_insn->detail->sparc, 0, offsetof(cs_sparc, operands));
}

Result = decodeInstruction_4(DecoderTableSparc32, MI, Insn, address,
Expand Down
2 changes: 1 addition & 1 deletion arch/SystemZ/SystemZDisassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ bool SystemZ_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst
return MCDisassembler_Fail;

if (MI->flat_insn->detail) {
memset(&MI->flat_insn->detail->sysz, 0, offset_of(cs_sysz, operands));
memset(&MI->flat_insn->detail->sysz, 0, offsetof(cs_sysz, operands));
}

memcpy(Bytes, code, *size);
Expand Down
2 changes: 1 addition & 1 deletion arch/X86/X86Disassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ bool X86_getInstruction(csh ud, const uint8_t *code, size_t code_len,
info.size = code_len;
info.offset = address;

memset(&insn, 0, offset_of(InternalInstruction, reader));
memset(&insn, 0, offsetof(InternalInstruction, reader));

if (instr->flat_insn->detail) {
instr->flat_insn->detail->x86.op_count = 0;
Expand Down
2 changes: 1 addition & 1 deletion arch/XCore/XCoreDisassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ bool XCore_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst *
}

if (MI->flat_insn->detail) {
memset(&MI->flat_insn->detail->xcore, 0, offset_of(cs_xcore, operands));
memset(&MI->flat_insn->detail->xcore, 0, offsetof(cs_xcore, operands));
}

// Calling the auto-generated decoder function.
Expand Down
2 changes: 1 addition & 1 deletion cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ size_t cs_disasm_ex(csh ud, const uint8_t *buffer, size_t size, uint64_t offset,
}

total = tmp;
insn_cache = total + total_size - (sizeof(cs_insn) * INSN_CACHE_SIZE);
insn_cache = (cs_insn *)((char *)total + total_size - (sizeof(cs_insn) * INSN_CACHE_SIZE));

// reset f back to 0
f = 0;
Expand Down
3 changes: 1 addition & 2 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef CS_UTILS_H
#define CS_UTILS_H

#include <stddef.h>
#include "include/capstone.h"
#include "cs_priv.h"

Expand Down Expand Up @@ -47,7 +48,5 @@ char *cs_strdup(const char *str);

#define MIN(x, y) ((x) < (y) ? (x) : (y))

#define offset_of(st, member) __builtin_offsetof(st, member)

#endif

0 comments on commit cae09bf

Please sign in to comment.