From dd62f125c359b37d71be6ccf873177c1a108d015 Mon Sep 17 00:00:00 2001 From: River City Ransomware Date: Fri, 19 Jan 2018 18:01:41 -0500 Subject: [PATCH] Fixes some cast warnings, partial port of citra #3064 (#106) * Fixes some cast warnings, partially fixes citra #3064 * Converted casts to uint32_t to u32 * Ran clang-format --- src/core/arm/dynarmic/arm_dynarmic.cpp | 6 ++--- src/core/core_timing.cpp | 4 ++-- src/core/gdbstub/gdbstub.cpp | 27 +++++++++++----------- src/core/hle/kernel/condition_variable.cpp | 2 +- src/core/hle/kernel/hle_ipc.cpp | 2 +- src/core/hle/service/vi/vi.cpp | 2 +- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index 2ad48dcc7d..72c54f9840 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp @@ -46,7 +46,7 @@ public: ARM_Interface::ThreadContext ctx; parent.SaveContext(ctx); parent.inner_unicorn.LoadContext(ctx); - parent.inner_unicorn.ExecuteInstructions(num_instructions); + parent.inner_unicorn.ExecuteInstructions(static_cast(num_instructions)); parent.inner_unicorn.SaveContext(ctx); parent.LoadContext(ctx); num_interpreted_instructions += num_instructions; @@ -163,9 +163,9 @@ void ARM_Dynarmic::LoadContext(const ARM_Interface::ThreadContext& ctx) { jit.SetRegisters(ctx.cpu_registers); jit.SetSP(ctx.sp); jit.SetPC(ctx.pc); - jit.SetPstate(ctx.cpsr); + jit.SetPstate(static_cast(ctx.cpsr)); jit.SetVectors(ctx.fpu_registers); - jit.SetFpcr(ctx.fpscr); + jit.SetFpcr(static_cast(ctx.fpscr)); cb->tpidrr0_el0 = ctx.tls_address; } diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index a0656f0a82..9e1bf2d0e5 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -122,7 +122,7 @@ u64 GetTicks() { } void AddTicks(u64 ticks) { - downcount -= ticks; + downcount -= static_cast(ticks); } u64 GetIdleTicks() { @@ -208,7 +208,7 @@ void Advance() { Event evt = std::move(event_queue.front()); std::pop_heap(event_queue.begin(), event_queue.end(), std::greater()); event_queue.pop_back(); - evt.type->callback(evt.userdata, global_timer - evt.time); + evt.type->callback(evt.userdata, static_cast(global_timer - evt.time)); } is_global_timer_sane = false; diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 05c872d894..2f3ccb689d 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -183,11 +183,11 @@ static u8 NibbleToHex(u8 n) { } /** -* Converts input hex string characters into an array of equivalent of u8 bytes. -* -* @param src Pointer to array of output hex string characters. -* @param len Length of src array. -*/ + * Converts input hex string characters into an array of equivalent of u8 bytes. + * + * @param src Pointer to array of output hex string characters. + * @param len Length of src array. + */ static u32 HexToInt(const u8* src, size_t len) { u32 output = 0; while (len-- > 0) { @@ -299,17 +299,17 @@ static std::map& GetBreakpointList(BreakpointType type) { static void RemoveBreakpoint(BreakpointType type, PAddr addr) { std::map& p = GetBreakpointList(type); - auto bp = p.find(addr); + auto bp = p.find(static_cast(addr)); if (bp != p.end()) { LOG_DEBUG(Debug_GDBStub, "gdb: removed a breakpoint: %08x bytes at %08x of type %d\n", bp->second.len, bp->second.addr, type); - p.erase(addr); + p.erase(static_cast(addr)); } } BreakpointAddress GetNextBreakpointFromAddress(PAddr addr, BreakpointType type) { std::map& p = GetBreakpointList(type); - auto next_breakpoint = p.lower_bound(addr); + auto next_breakpoint = p.lower_bound(static_cast(addr)); BreakpointAddress breakpoint; if (next_breakpoint != p.end()) { @@ -330,7 +330,7 @@ bool CheckBreakpoint(PAddr addr, BreakpointType type) { std::map& p = GetBreakpointList(type); - auto bp = p.find(addr); + auto bp = p.find(static_cast(addr)); if (bp != p.end()) { u32 len = bp->second.len; @@ -452,7 +452,8 @@ static void SendSignal(u32 signal) { std::string buffer = Common::StringFromFormat("T%02x%02x:%08x;%02x:%08x;", latest_signal, 15, - htonl(Core::CPU().GetPC()), 13, htonl(Core::CPU().GetReg(13))); + htonl(static_cast(Core::CPU().GetPC())), 13, + htonl(static_cast(Core::CPU().GetReg(13)))); LOG_DEBUG(Debug_GDBStub, "Response: %s", buffer.c_str()); SendReply(buffer.c_str()); } @@ -539,7 +540,7 @@ static void ReadRegister() { } if (id <= R15_REGISTER) { - IntToGdbHex(reply, Core::CPU().GetReg(id)); + IntToGdbHex(reply, static_cast(Core::CPU().GetReg(static_cast(id)))); } else if (id == CPSR_REGISTER) { IntToGdbHex(reply, Core::CPU().GetCPSR()); } else if (id > CPSR_REGISTER && id < FPSCR_REGISTER) { @@ -563,7 +564,7 @@ static void ReadRegisters() { u8* bufptr = buffer; for (int reg = 0; reg <= R15_REGISTER; reg++) { - IntToGdbHex(bufptr + reg * CHAR_BIT, Core::CPU().GetReg(reg)); + IntToGdbHex(bufptr + reg * CHAR_BIT, static_cast(Core::CPU().GetReg(reg))); } bufptr += (16 * CHAR_BIT); @@ -1034,4 +1035,4 @@ bool GetCpuStepFlag() { void SetCpuStepFlag(bool is_step) { step_loop = is_step; } -}; +}; // namespace GDBStub diff --git a/src/core/hle/kernel/condition_variable.cpp b/src/core/hle/kernel/condition_variable.cpp index 5942eae61d..5616663847 100644 --- a/src/core/hle/kernel/condition_variable.cpp +++ b/src/core/hle/kernel/condition_variable.cpp @@ -43,7 +43,7 @@ void ConditionVariable::Acquire(Thread* thread) { ResultCode ConditionVariable::Release(s32 target) { if (target == -1) { // When -1, wake up all waiting threads - SetAvailableCount(GetWaitingThreads().size()); + SetAvailableCount(static_cast(GetWaitingThreads().size())); WakeupAllWaitingThreads(); } else { // Otherwise, wake up just a single thread diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 73bb6a8be6..3899dad096 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -210,7 +210,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf, P for (auto& object : domain_objects) { request_handlers.emplace_back(object); - dst_cmdbuf[domain_offset++] = request_handlers.size(); + dst_cmdbuf[domain_offset++] = static_cast(request_handlers.size()); } } return RESULT_SUCCESS; diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 015fb164e1..c624e734e3 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -95,7 +95,7 @@ public: Header header{}; header.data_offset = sizeof(Header); - header.data_size = write_index - sizeof(Header); + header.data_size = static_cast(write_index - sizeof(Header)); std::memcpy(buffer.data(), &header, sizeof(Header)); return buffer;