Skip to content

Commit

Permalink
fix more MSVC warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aquynh committed Aug 26, 2014
1 parent 07c92ec commit 4b6b15f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions arch/AArch64/AArch64InstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ static void printTypedVectorList(MCInst *MI, unsigned OpNum, SStream *O, unsigne
arm64_vess vess = 0;

if (NumLanes) {
snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, LaneKind);
cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, LaneKind);
switch(LaneKind) {
default: break;
case 'b':
Expand Down Expand Up @@ -1633,7 +1633,7 @@ static void printTypedVectorList(MCInst *MI, unsigned OpNum, SStream *O, unsigne
break;
}
} else {
snprintf(Suffix, sizeof(Suffix), ".%c", LaneKind);
cs_snprintf(Suffix, sizeof(Suffix), ".%c", LaneKind);
switch(LaneKind) {
default: break;
case 'b':
Expand Down
2 changes: 1 addition & 1 deletion arch/AArch64/AArch64Mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -14959,7 +14959,7 @@ void arm64_op_addImm(MCInst *MI, int64_t imm)
{
if (MI->csh->detail) {
MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = imm;
MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int)imm;
MI->flat_insn->detail->arm64.op_count++;
}
}
Expand Down
12 changes: 6 additions & 6 deletions arch/Mips/MipsDisassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ static DecodeStatus DecodeAddiGroupBranch_4(MCInst *MI, uint32_t insn,

uint32_t Rs = fieldFromInstruction(insn, 21, 5);
uint32_t Rt = fieldFromInstruction(insn, 16, 5);
uint32_t Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) << 2;
uint32_t Imm = (uint32_t)SignExtend64(fieldFromInstruction(insn, 0, 16), 16) << 2;
bool HasRs = false;

if (Rs >= Rt) {
Expand Down Expand Up @@ -532,7 +532,7 @@ static DecodeStatus DecodeDaddiGroupBranch_4(MCInst *MI, uint32_t insn,

uint32_t Rs = fieldFromInstruction(insn, 21, 5);
uint32_t Rt = fieldFromInstruction(insn, 16, 5);
uint32_t Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) << 2;
uint32_t Imm = (uint32_t)SignExtend64(fieldFromInstruction(insn, 0, 16), 16) << 2;
bool HasRs = false;

if (Rs >= Rt) {
Expand Down Expand Up @@ -569,7 +569,7 @@ static DecodeStatus DecodeBlezlGroupBranch_4(MCInst *MI, uint32_t insn,

uint32_t Rs = fieldFromInstruction(insn, 21, 5);
uint32_t Rt = fieldFromInstruction(insn, 16, 5);
uint32_t Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) << 2;
uint32_t Imm = (uint32_t)SignExtend64(fieldFromInstruction(insn, 0, 16), 16) << 2;
bool HasRs = false;

if (Rt == 0)
Expand Down Expand Up @@ -611,7 +611,7 @@ static DecodeStatus DecodeBgtzlGroupBranch_4(MCInst *MI, uint32_t insn,

uint32_t Rs = fieldFromInstruction(insn, 21, 5);
uint32_t Rt = fieldFromInstruction(insn, 16, 5);
uint32_t Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) << 2;
uint32_t Imm = (uint32_t)SignExtend64(fieldFromInstruction(insn, 0, 16), 16) << 2;

if (Rt == 0)
return MCDisassembler_Fail;
Expand Down Expand Up @@ -649,7 +649,7 @@ static DecodeStatus DecodeBgtzGroupBranch_4(MCInst *MI, uint32_t insn,

uint32_t Rs = fieldFromInstruction(insn, 21, 5);
uint32_t Rt = fieldFromInstruction(insn, 16, 5);
uint32_t Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) << 2;
uint32_t Imm = (uint32_t)SignExtend64(fieldFromInstruction(insn, 0, 16), 16) << 2;
bool HasRs = false;
bool HasRt = false;

Expand Down Expand Up @@ -695,7 +695,7 @@ static DecodeStatus DecodeBlezGroupBranch_4(MCInst *MI, uint32_t insn,

uint32_t Rs = fieldFromInstruction(insn, 21, 5);
uint32_t Rt = fieldFromInstruction(insn, 16, 5);
uint32_t Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) << 2;
uint32_t Imm = (uint32_t)SignExtend64(fieldFromInstruction(insn, 0, 16), 16) << 2;
bool HasRs = false;

if (Rt == 0)
Expand Down
4 changes: 4 additions & 0 deletions arch/Sparc/SparcInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

#ifdef CAPSTONE_HAS_SPARC

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ size_t cs_disasm_ex(csh ud, const uint8_t *buffer, size_t size, uint64_t offset,

if (handle->skipdata_setup.callback) {
skipdata_bytes = handle->skipdata_setup.callback(buffer_org, size_org,
offset - offset_org, handle->skipdata_setup.user_data);
(size_t)(offset - offset_org), handle->skipdata_setup.user_data);
if (skipdata_bytes > size)
// remaining data is not enough
break;
Expand Down
13 changes: 13 additions & 0 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,16 @@ char *cs_strdup(const char *str)

return (char *)memmove(new, str, len);
}

// we need this since Windows doesnt have snprintf()
int cs_snprintf(char *buffer, size_t size, const char *fmt, ...)
{
int ret;

va_list ap;
va_start(ap, fmt);
ret = cs_vsnprintf(buffer, size, fmt, ap);
va_end(ap);

return ret;
}
3 changes: 3 additions & 0 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@ char *cs_strdup(const char *str);

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

// we need this since Windows doesnt have snprintf()
int cs_snprintf(char *buffer, size_t size, const char *fmt, ...);

#endif

0 comments on commit 4b6b15f

Please sign in to comment.