buffer fixes found via cppcheck/tetsuo--

This commit is contained in:
booto 2013-06-18 13:17:50 +08:00
parent c57a90c5b5
commit a518a1cbdc
2 changed files with 15 additions and 13 deletions

View File

@ -214,7 +214,6 @@ clear_buffer:
template <typename T> template <typename T>
void PrintObject(const T &Obj) void PrintObject(const T &Obj)
{ {
char byte[2] = {0};
std::stringstream ss; std::stringstream ss;
u8 *o = (u8 *)&Obj; u8 *o = (u8 *)&Obj;
@ -223,16 +222,17 @@ void PrintObject(const T &Obj)
CompileTimeAssert<sizeof(ZeldaVoicePB) == 0x180> ensure_zpb_size_correct; CompileTimeAssert<sizeof(ZeldaVoicePB) == 0x180> ensure_zpb_size_correct;
(void)ensure_zpb_size_correct; (void)ensure_zpb_size_correct;
ss << std::hex;
for (size_t i = 0; i < sizeof(T); i++) for (size_t i = 0; i < sizeof(T); i++)
{ {
if((i > 0) && ((i & 1) == 0)) if((i & 1) == 0)
ss << " "; ss << ' ';
ss.width(2);
sprintf(byte, "%02X", Common::swap16(o[i])); ss.fill('0');
ss << byte; ss << Common::swap16(o[i]);
} }
DEBUG_LOG(DSPHLE, "AFC PB: %s", ss.str().c_str()); DEBUG_LOG(DSPHLE, "AFC PB:%s", ss.str().c_str());
} }
void CUCode_Zelda::RenderVoice_AFC(ZeldaVoicePB &PB, s16 *_Buffer, int _Size) void CUCode_Zelda::RenderVoice_AFC(ZeldaVoicePB &PB, s16 *_Buffer, int _Size)

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2 // Licensed under GPLv2
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <sstream>
#include "JitBase.h" #include "JitBase.h"
#include "PowerPCDisasm.h" #include "PowerPCDisasm.h"
#include "disasm.h" #include "disasm.h"
@ -54,14 +56,14 @@ void LogGeneratedX86(int size, PPCAnalyst::CodeBuffer *code_buffer, const u8 *no
if (b->codeSize <= 250) if (b->codeSize <= 250)
{ {
char x86code[500] = ""; std::stringstream ss;
ss << std::hex;
for (u8 i = 0; i <= b->codeSize; i++) for (u8 i = 0; i <= b->codeSize; i++)
{ {
char opcHex[2] = ""; ss.width(2);
u8 opc = *(normalEntry + i); ss.fill('0');
sprintf(opcHex, "%02x", opc); ss << (u32)*(normalEntry + i);
strncat(x86code, opcHex, 2);
} }
DEBUG_LOG(DYNA_REC,"IR_X86 bin: %s\n\n\n", x86code); DEBUG_LOG(DYNA_REC,"IR_X86 bin: %s\n\n\n", ss.str().c_str());
} }
} }