From a518a1cbdcc311af1b01eeb940b3fb57f6f15554 Mon Sep 17 00:00:00 2001 From: booto Date: Tue, 18 Jun 2013 13:17:50 +0800 Subject: [PATCH] buffer fixes found via cppcheck/tetsuo-- --- .../Src/HW/DSPHLE/UCodes/UCode_Zelda_Voice.cpp | 14 +++++++------- Source/Core/Core/Src/PowerPC/JitCommon/JitBase.cpp | 14 ++++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_Zelda_Voice.cpp b/Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_Zelda_Voice.cpp index 6e590d1a83..a684bb0c02 100644 --- a/Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_Zelda_Voice.cpp +++ b/Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_Zelda_Voice.cpp @@ -214,7 +214,6 @@ clear_buffer: template void PrintObject(const T &Obj) { - char byte[2] = {0}; std::stringstream ss; u8 *o = (u8 *)&Obj; @@ -223,16 +222,17 @@ void PrintObject(const T &Obj) CompileTimeAssert ensure_zpb_size_correct; (void)ensure_zpb_size_correct; + ss << std::hex; for (size_t i = 0; i < sizeof(T); i++) { - if((i > 0) && ((i & 1) == 0)) - ss << " "; - - sprintf(byte, "%02X", Common::swap16(o[i])); - ss << byte; + if((i & 1) == 0) + ss << ' '; + ss.width(2); + ss.fill('0'); + 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) diff --git a/Source/Core/Core/Src/PowerPC/JitCommon/JitBase.cpp b/Source/Core/Core/Src/PowerPC/JitCommon/JitBase.cpp index 6390b3ea5d..46644f2fc9 100644 --- a/Source/Core/Core/Src/PowerPC/JitCommon/JitBase.cpp +++ b/Source/Core/Core/Src/PowerPC/JitCommon/JitBase.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include + #include "JitBase.h" #include "PowerPCDisasm.h" #include "disasm.h" @@ -54,14 +56,14 @@ void LogGeneratedX86(int size, PPCAnalyst::CodeBuffer *code_buffer, const u8 *no if (b->codeSize <= 250) { - char x86code[500] = ""; + std::stringstream ss; + ss << std::hex; for (u8 i = 0; i <= b->codeSize; i++) { - char opcHex[2] = ""; - u8 opc = *(normalEntry + i); - sprintf(opcHex, "%02x", opc); - strncat(x86code, opcHex, 2); + ss.width(2); + ss.fill('0'); + ss << (u32)*(normalEntry + i); } - 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()); } }