From 62d36f98331067e472188f6c020c2ccd808f48cf Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Fri, 22 Jun 2012 16:56:56 +0100 Subject: [PATCH] Removed the addr_t conversion operators from FixedWidthPointer which makes comparison against NULL work properly. --- .../private/kernel/util/FixedWidthPointer.h | 24 +++++++++++-------- src/system/boot/platform/bios_ia32/debug.cpp | 2 +- src/system/boot/platform/bios_ia32/smp.cpp | 6 ++--- src/system/boot/platform/bios_ia32/video.cpp | 2 +- .../boot/platform/generic/video_splash.cpp | 4 ++-- .../boot/platform/openfirmware/video.cpp | 2 +- src/system/boot/platform/u-boot/serial.cpp | 2 +- src/system/kernel/arch/x86/apic.cpp | 2 +- src/system/kernel/arch/x86/ioapic.cpp | 2 +- .../kernel/arch/x86/timers/x86_hpet.cpp | 2 +- src/system/kernel/debug/debug.cpp | 6 ++--- .../kernel/debug/frame_buffer_console.cpp | 2 +- 12 files changed, 30 insertions(+), 26 deletions(-) diff --git a/headers/private/kernel/util/FixedWidthPointer.h b/headers/private/kernel/util/FixedWidthPointer.h index b6e9662e72..56d88afaef 100644 --- a/headers/private/kernel/util/FixedWidthPointer.h +++ b/headers/private/kernel/util/FixedWidthPointer.h @@ -25,11 +25,6 @@ public: return (Type *)(addr_t)fValue; } - operator addr_t() const - { - return (addr_t)fValue; - } - Type& operator*() const { return *(Type *)*this; @@ -90,11 +85,6 @@ public: return (OtherType*)(addr_t)fValue; } - operator addr_t() const - { - return (addr_t)fValue; - } - FixedWidthPointer& operator=(const FixedWidthPointer& p) { fValue = p.fValue; @@ -121,5 +111,19 @@ private: uint64 fValue; } _PACKED; +template +inline bool +operator==(const FixedWidthPointer& a, void* b) +{ + return a.Get() == (addr_t)b; +} + +template +inline bool +operator!=(const FixedWidthPointer& a, void* b) +{ + return a.Get() != (addr_t)b; +} + #endif /* KERNEL_UTIL_FIXED_WIDTH_POINTER_H */ diff --git a/src/system/boot/platform/bios_ia32/debug.cpp b/src/system/boot/platform/bios_ia32/debug.cpp index deb389dce5..73d2906415 100644 --- a/src/system/boot/platform/bios_ia32/debug.cpp +++ b/src/system/boot/platform/bios_ia32/debug.cpp @@ -162,7 +162,7 @@ debug_cleanup(void) if (!gKernelArgs.keep_debug_output_buffer) { gKernelArgs.debug_output = kernel_args_malloc(sBufferPosition); - if (gKernelArgs.debug_output) { + if (gKernelArgs.debug_output != NULL) { memcpy(gKernelArgs.debug_output, sBuffer, sBufferPosition); gKernelArgs.debug_size = sBufferPosition; } diff --git a/src/system/boot/platform/bios_ia32/smp.cpp b/src/system/boot/platform/bios_ia32/smp.cpp index f31af15f2a..2944655a99 100644 --- a/src/system/boot/platform/bios_ia32/smp.cpp +++ b/src/system/boot/platform/bios_ia32/smp.cpp @@ -60,21 +60,21 @@ static int smp_get_current_cpu(void); static uint32 apic_read(uint32 offset) { - return *(volatile uint32 *)((addr_t)gKernelArgs.arch_args.apic + offset); + return *(volatile uint32 *)((addr_t)(void *)gKernelArgs.arch_args.apic + offset); } static void apic_write(uint32 offset, uint32 data) { - *(volatile uint32 *)((addr_t)gKernelArgs.arch_args.apic + offset) = data; + *(volatile uint32 *)((addr_t)(void *)gKernelArgs.arch_args.apic + offset) = data; } static int smp_get_current_cpu(void) { - if (!gKernelArgs.arch_args.apic) + if (gKernelArgs.arch_args.apic == NULL) return 0; uint8 apicID = apic_read(APIC_ID) >> 24; diff --git a/src/system/boot/platform/bios_ia32/video.cpp b/src/system/boot/platform/bios_ia32/video.cpp index be634ff29a..fa9b1fba8c 100644 --- a/src/system/boot/platform/bios_ia32/video.cpp +++ b/src/system/boot/platform/bios_ia32/video.cpp @@ -957,7 +957,7 @@ platform_init_video(void) } gKernelArgs.edid_info = kernel_args_malloc(sizeof(edid1_info)); - if (gKernelArgs.edid_info) + if (gKernelArgs.edid_info != NULL) memcpy(gKernelArgs.edid_info, &info, sizeof(edid1_info)); } diff --git a/src/system/boot/platform/generic/video_splash.cpp b/src/system/boot/platform/generic/video_splash.cpp index ceebb2eab1..5d1c41166a 100644 --- a/src/system/boot/platform/generic/video_splash.cpp +++ b/src/system/boot/platform/generic/video_splash.cpp @@ -146,7 +146,7 @@ video_display_splash(addr_t frameBuffer) // pointer into the lower half of the icons image data gKernelArgs.boot_splash = (uint8*)kernel_args_malloc(uncompressedSize); - if (!gKernelArgs.boot_splash) + if (gKernelArgs.boot_splash == NULL) return B_NO_MEMORY; uncompress(kSplashIcons8BitCompressedImage, sizeof(kSplashIcons8BitCompressedImage), @@ -159,7 +159,7 @@ video_display_splash(addr_t frameBuffer) // pointer into the lower half of the icons image data gKernelArgs.boot_splash = (uint8*)kernel_args_malloc(uncompressedSize); - if (!gKernelArgs.boot_splash) + if (gKernelArgs.boot_splash == NULL) return B_NO_MEMORY; uncompress(kSplashIcons24BitCompressedImage, sizeof(kSplashIcons24BitCompressedImage), diff --git a/src/system/boot/platform/openfirmware/video.cpp b/src/system/boot/platform/openfirmware/video.cpp index d996cd9035..639723d09b 100644 --- a/src/system/boot/platform/openfirmware/video.cpp +++ b/src/system/boot/platform/openfirmware/video.cpp @@ -126,7 +126,7 @@ platform_init_video(void) edid_dump(&info); #endif gKernelArgs.edid_info = kernel_args_malloc(sizeof(edid1_info)); - if (gKernelArgs.edid_info) + if (gKernelArgs.edid_info != NULL) memcpy(gKernelArgs.edid_info, &info, sizeof(edid1_info)); } diff --git a/src/system/boot/platform/u-boot/serial.cpp b/src/system/boot/platform/u-boot/serial.cpp index 4ba65ef26a..12c6357d26 100644 --- a/src/system/boot/platform/u-boot/serial.cpp +++ b/src/system/boot/platform/u-boot/serial.cpp @@ -83,7 +83,7 @@ serial_cleanup(void) return; gKernelArgs.debug_output = kernel_args_malloc(sBufferPosition); - if (gKernelArgs.debug_output) { + if (gKernelArgs.debug_output != NULL) { memcpy(gKernelArgs.debug_output, sBuffer, sBufferPosition); gKernelArgs.debug_size = sBufferPosition; } diff --git a/src/system/kernel/arch/x86/apic.cpp b/src/system/kernel/arch/x86/apic.cpp index 12492003ae..2c83935402 100644 --- a/src/system/kernel/arch/x86/apic.cpp +++ b/src/system/kernel/arch/x86/apic.cpp @@ -68,7 +68,7 @@ apic_disable_local_ints() status_t apic_init(kernel_args *args) { - if (!args->arch_args.apic) + if (args->arch_args.apic == NULL) return B_NO_INIT; sLocalAPIC = args->arch_args.apic; diff --git a/src/system/kernel/arch/x86/ioapic.cpp b/src/system/kernel/arch/x86/ioapic.cpp index fa23b17571..6d40b1645b 100644 --- a/src/system/kernel/arch/x86/ioapic.cpp +++ b/src/system/kernel/arch/x86/ioapic.cpp @@ -650,7 +650,7 @@ ioapic_init(kernel_args* args) &ioapic_end_of_interrupt }; - if (!args->arch_args.apic) + if (args->arch_args.apic == NULL) return; if (args->arch_args.ioapic_phys == 0) { diff --git a/src/system/kernel/arch/x86/timers/x86_hpet.cpp b/src/system/kernel/arch/x86/timers/x86_hpet.cpp index e75a8795e0..d5dfa48693 100644 --- a/src/system/kernel/arch/x86/timers/x86_hpet.cpp +++ b/src/system/kernel/arch/x86/timers/x86_hpet.cpp @@ -217,7 +217,7 @@ hpet_init(struct kernel_args *args) /* hpet_acpi_probe() through a similar "scan spots" table to that of smp.cpp. Seems to be the most elegant solution right now. */ - if (!args->arch_args.hpet) + if (args->arch_args.hpet == NULL) return B_ERROR; if (sHPETRegs == NULL) { diff --git a/src/system/kernel/debug/debug.cpp b/src/system/kernel/debug/debug.cpp index 0a4d759dd1..791c827448 100644 --- a/src/system/kernel/debug/debug.cpp +++ b/src/system/kernel/debug/debug.cpp @@ -1384,7 +1384,7 @@ syslog_init_post_vm(struct kernel_args* args) } } else { // create an area for the debug syslog buffer - void* base = (void*)ROUNDDOWN((addr_t)args->debug_output, B_PAGE_SIZE); + void* base = (void*)ROUNDDOWN((addr_t)(void *)args->debug_output, B_PAGE_SIZE); size_t size = ROUNDUP(args->debug_size, B_PAGE_SIZE); area_id area = create_area("syslog debug", &base, B_EXACT_ADDRESS, size, B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); @@ -1401,7 +1401,7 @@ syslog_init_post_vm(struct kernel_args* args) sSyslogMessage->ident[0] = '\0'; //strcpy(sSyslogMessage->ident, "KERNEL"); - if (args->debug_output) + if (args->debug_output != NULL) syslog_write((const char*)args->debug_output, args->debug_size, false); char revisionBuffer[64]; @@ -1431,7 +1431,7 @@ err1: static status_t syslog_init(struct kernel_args* args) { - if (!args->keep_debug_output_buffer || !args->debug_output) + if (!args->keep_debug_output_buffer || args->debug_output == NULL) return B_OK; sSyslogBuffer = create_ring_buffer_etc(args->debug_output, args->debug_size, diff --git a/src/system/kernel/debug/frame_buffer_console.cpp b/src/system/kernel/debug/frame_buffer_console.cpp index 205f50d9d5..5a1f67d865 100644 --- a/src/system/kernel/debug/frame_buffer_console.cpp +++ b/src/system/kernel/debug/frame_buffer_console.cpp @@ -442,7 +442,7 @@ frame_buffer_console_init(kernel_args* args) add_boot_item(VESA_MODES_BOOT_INFO, sVesaModes, args->vesa_modes_size); } - if (args->edid_info) { + if (args->edid_info != NULL) { edid1_info* info = (edid1_info*)malloc(sizeof(edid1_info)); if (info != NULL) { memcpy(info, args->edid_info, sizeof(edid1_info));