mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-13 04:38:24 +00:00
Fix potential buffer overflow on win32.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129214 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -128,9 +128,9 @@ public:
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
//
|
//
|
||||||
// LLVMDisasmInstruction() disassmbles a single instruction using the
|
// LLVMDisasmInstruction() disassembles a single instruction using the
|
||||||
// disassembler context specified in the parameter DC. The bytes of the
|
// disassembler context specified in the parameter DC. The bytes of the
|
||||||
// instuction are specified in the parameter Bytes, and contains at least
|
// instruction are specified in the parameter Bytes, and contains at least
|
||||||
// BytesSize number of bytes. The instruction is at the address specified by
|
// BytesSize number of bytes. The instruction is at the address specified by
|
||||||
// the PC parameter. If a valid instruction can be disassembled its string is
|
// the PC parameter. If a valid instruction can be disassembled its string is
|
||||||
// returned indirectly in OutString which whos size is specified in the
|
// returned indirectly in OutString which whos size is specified in the
|
||||||
@ -155,16 +155,13 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes,
|
|||||||
|
|
||||||
std::string InsnStr;
|
std::string InsnStr;
|
||||||
raw_string_ostream OS(InsnStr);
|
raw_string_ostream OS(InsnStr);
|
||||||
raw_ostream &Out = OS;
|
IP->printInst(&Inst, OS);
|
||||||
IP->printInst(&Inst, Out);
|
OS.flush();
|
||||||
|
|
||||||
|
size_t OutputSize = std::min(OutStringSize-1, InsnStr.size());
|
||||||
|
std::memcpy(OutString, InsnStr.data(), OutputSize);
|
||||||
|
OutString[OutputSize] = '\0'; // Terminate string.
|
||||||
|
|
||||||
std::string p;
|
|
||||||
p = OS.str();
|
|
||||||
#ifdef LLVM_ON_WIN32
|
|
||||||
sprintf(OutString, "%s", p.c_str());
|
|
||||||
#else
|
|
||||||
snprintf(OutString, OutStringSize, "%s", p.c_str());
|
|
||||||
#endif
|
|
||||||
return Size;
|
return Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user