From fe05b1de127883399f13b0e2ea1aaae3d40607ff Mon Sep 17 00:00:00 2001 From: joevt Date: Fri, 2 Jun 2023 01:23:21 -0700 Subject: [PATCH] Fix compiler warnings. Xcode build has compiler warnings involving loss of precision. Remove them by adding type casts. Check results in some cases for overflow. --- cpu/ppc/ppcopcodes.cpp | 2 +- devices/common/scsi/scsihd.cpp | 6 +++++- devices/video/atimach64gx.cpp | 8 ++++---- devices/video/atirage.cpp | 8 ++++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cpu/ppc/ppcopcodes.cpp b/cpu/ppc/ppcopcodes.cpp index 96ac3a2..e944c7a 100644 --- a/cpu/ppc/ppcopcodes.cpp +++ b/cpu/ppc/ppcopcodes.cpp @@ -909,7 +909,7 @@ static inline uint32_t calc_dec_value() { uint32_t dec_adj_lo; uint64_t diff = get_virt_time_ns() - dec_wr_timestamp; _u32xu64(tbr_freq_ghz, diff, dec_adj, dec_adj_lo); - return (dec_wr_value - dec_adj); + return (dec_wr_value - static_cast(dec_adj)); } static void update_timebase(uint64_t mask, uint64_t new_val) diff --git a/devices/common/scsi/scsihd.cpp b/devices/common/scsi/scsihd.cpp index 1820eef..82dcc63 100644 --- a/devices/common/scsi/scsihd.cpp +++ b/devices/common/scsi/scsihd.cpp @@ -46,7 +46,11 @@ void ScsiHardDisk::insert_image(std::string filename) { ABORT_F("%s: could not open image file %s", this->name.c_str(), filename.c_str()); this->img_size = this->hdd_img.size(); - this->total_blocks = (this->img_size + HDD_SECTOR_SIZE - 1) / HDD_SECTOR_SIZE; + uint64_t tb = (this->img_size + HDD_SECTOR_SIZE - 1) / HDD_SECTOR_SIZE; + this->total_blocks = static_cast(tb); + if (this->total_blocks < 0 || tb != this->total_blocks) { + ABORT_F("ScsiHardDisk: file size is too large"); + } } void ScsiHardDisk::process_command() { diff --git a/devices/video/atimach64gx.cpp b/devices/video/atimach64gx.cpp index 2316942..4344017 100644 --- a/devices/video/atimach64gx.cpp +++ b/devices/video/atimach64gx.cpp @@ -1,6 +1,6 @@ /* DingusPPC - The Experimental PowerPC Macintosh emulator -Copyright (C) 2018-23 divingkatae and maximum +Copyright (C) 2018-24 divingkatae and maximum (theweirdo) spatium (Contact divingkatae#1017 or powermax#2286 on Discord for more info) @@ -174,12 +174,12 @@ uint32_t AtiMach64Gx::read_reg(uint32_t reg_offset, uint32_t size) uint64_t result = this->regs[reg_offset >> 2]; if (!offset && size == 4) { // fast path - return result; + return static_cast(result); } else { // slow path if ((offset + size) > 4) { result |= (uint64_t)(this->regs[(reg_offset >> 2) + 1]) << 32; } - return extract_bits(result, offset * 8, size * 8); + return static_cast(extract_bits(result, offset * 8, size * 8)); } } @@ -197,7 +197,7 @@ void AtiMach64Gx::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size) } uint64_t old_val = this->regs[reg_offset]; insert_bits(old_val, value, offset * 8, size * 8); - value = old_val; + value = static_cast(old_val); } switch (reg_offset) { diff --git a/devices/video/atirage.cpp b/devices/video/atirage.cpp index f25769f..37f2919 100644 --- a/devices/video/atirage.cpp +++ b/devices/video/atirage.cpp @@ -1,6 +1,6 @@ /* DingusPPC - The Experimental PowerPC Macintosh emulator -Copyright (C) 2018-23 divingkatae and maximum +Copyright (C) 2018-24 divingkatae and maximum (theweirdo) spatium (Contact divingkatae#1017 or powermax#2286 on Discord for more info) @@ -251,12 +251,12 @@ uint32_t ATIRage::read_reg(uint32_t reg_offset, uint32_t size) { } if (!offset && size == 4) { // fast path - return result; + return static_cast(result); } else { // slow path if ((offset + size) > 4) { result |= (uint64_t)(this->regs[(reg_offset >> 2) + 1]) << 32; } - return extract_bits(result, offset * 8, size * 8); + return static_cast(extract_bits(result, offset * 8, size * 8)); } } @@ -270,7 +270,7 @@ void ATIRage::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size) { } uint64_t old_val = this->regs[reg_offset]; insert_bits(old_val, value, offset * 8, size * 8); - value = old_val; + value = static_cast(old_val); } switch (reg_offset) {