From 88859f4924b99c4917ee7c21085de8f329e76698 Mon Sep 17 00:00:00 2001 From: Nick Dowell Date: Mon, 18 Jul 2022 09:54:59 +0100 Subject: [PATCH] Enable -Wundef and fix warnings (#1438) --- Bugsnag.xcconfig | 2 +- Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m | 13 ++++++------- Bugsnag/Configuration/BugsnagConfiguration.m | 2 +- Bugsnag/Helpers/BSGAppHangDetector.m | 2 +- .../Source/KSCrash/Recording/BSG_Jailbreak.h | 2 +- .../Source/KSCrash/Recording/BSG_KSSystemInfo.m | 2 +- .../Sentry/BSG_KSCrashSentry_MachException.c | 2 +- .../Sentry/BSG_KSCrashSentry_NSException.m | 2 +- .../KSCrash/Recording/Tools/BSG_Symbolicate.c | 2 +- 9 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Bugsnag.xcconfig b/Bugsnag.xcconfig index 992e9bcba..97d351c86 100644 --- a/Bugsnag.xcconfig +++ b/Bugsnag.xcconfig @@ -91,7 +91,7 @@ CLANG_WARN__ARC_BRIDGE_CAST_NONARC = YES // -Warc-bridge-cas // Warning flags that have no dedicated Xcode build settings -WARNING_CFLAGS = -Wcast-qual -Wconditional-uninitialized -Wcustom-atomic-properties -Wdirect-ivar-access -Wdocumentation-unknown-command -Wformat-nonliteral -Widiomatic-parentheses -Wimplicit-int-float-conversion -Wimport-preprocessor-directive-pedantic -Wincomplete-implementation -Wmissing-variable-declarations -Wno-unknown-warning-option -Wnonportable-include-path -Wnullable-to-nonnull-conversion -Woverriding-method-mismatch -Wpointer-sign -Wswitch-enum -Wunused-macros +WARNING_CFLAGS = -Wcast-qual -Wconditional-uninitialized -Wcustom-atomic-properties -Wdirect-ivar-access -Wdocumentation-unknown-command -Wformat-nonliteral -Widiomatic-parentheses -Wimplicit-int-float-conversion -Wimport-preprocessor-directive-pedantic -Wincomplete-implementation -Wmissing-variable-declarations -Wno-unknown-warning-option -Wnonportable-include-path -Wnullable-to-nonnull-conversion -Woverriding-method-mismatch -Wpointer-sign -Wswitch-enum -Wundef -Wunused-macros // Some flags that were considered and rejected: // diff --git a/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m b/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m index 40b7c0e95..2a38c1c37 100644 --- a/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m +++ b/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m @@ -273,9 +273,8 @@ - (void)startListeningForStateChangeNotification:(NSNotificationName)notificatio } - (BOOL)tryAddSceneNotification:(NSNotification *)notification { -#if !TARGET_OS_WATCH && \ - ((defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0) || \ - (defined(__TVOS_13_0) && __TV_OS_VERSION_MAX_ALLOWED >= __TVOS_13_0)) +#if (TARGET_OS_IOS && defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0) || \ + (TARGET_OS_TV && defined(__TVOS_13_0) && __TV_OS_VERSION_MAX_ALLOWED >= __TVOS_13_0) if (@available(iOS 13.0, tvOS 13.0, *)) { if ([notification.name hasPrefix:@"UIScene"] && [notification.object isKindOfClass:UISCENE]) { UIScene *scene = notification.object; @@ -304,13 +303,12 @@ - (BOOL)tryAddSceneNotification:(NSNotification *)notification { - (BOOL)tryAddWindowNotification:(NSNotification *)notification { #if BSG_HAVE_WINDOW -#if !TARGET_OS_OSX && \ - (defined(__IPHONE_2_0) || (defined(__TVOS_9_0) && __TV_OS_VERSION_MAX_ALLOWED >= __TVOS_9_0)) +#if TARGET_OS_IOS || TARGET_OS_TV if ([notification.name hasPrefix:@"UIWindow"] && [notification.object isKindOfClass:UIWINDOW]) { UIWindow *window = notification.object; NSMutableDictionary *metadata = [NSMutableDictionary dictionary]; metadata[@"description"] = nullStringIfBlank(window.description); -#if !TARGET_OS_TV && (defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0) +#if TARGET_OS_IOS && defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0 if (@available(iOS 13.0, *)) { UIWindowScene *scene = window.windowScene; metadata[@"sceneTitle"] = nullStringIfBlank(scene.title); @@ -327,13 +325,14 @@ - (BOOL)tryAddWindowNotification:(NSNotification *)notification { return YES; } #endif + #if TARGET_OS_OSX if ([notification.name hasPrefix:@"NSWindow"] && [notification.object isKindOfClass:NSWINDOW]) { NSWindow *window = notification.object; NSMutableDictionary *metadata = [NSMutableDictionary dictionary]; metadata[@"description"] = nullStringIfBlank(window.description); metadata[@"title"] = nullStringIfBlank(window.title); -#if defined(__MAC_11_0) && __MAC_OS_VERSION_MAX_ALLOWED >= __MAC_11_0 +#if defined(__MAC_11_0) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_11_0 if (@available(macOS 11.0, *)) { metadata[@"subtitle"] = nullStringIfBlank(window.subtitle); } diff --git a/Bugsnag/Configuration/BugsnagConfiguration.m b/Bugsnag/Configuration/BugsnagConfiguration.m index 68cb73a5a..f4498a8a5 100644 --- a/Bugsnag/Configuration/BugsnagConfiguration.m +++ b/Bugsnag/Configuration/BugsnagConfiguration.m @@ -213,7 +213,7 @@ - (instancetype)initWithApiKey:(NSString *)apiKey { _telemetry = BSGTelemetryAll; NSString *releaseStage = nil; - #if DEBUG + #if defined(DEBUG) && DEBUG releaseStage = BSGKeyDevelopment; #else releaseStage = BSGKeyProduction; diff --git a/Bugsnag/Helpers/BSGAppHangDetector.m b/Bugsnag/Helpers/BSGAppHangDetector.m index 6fecff9f4..7ebea5f91 100644 --- a/Bugsnag/Helpers/BSGAppHangDetector.m +++ b/Bugsnag/Helpers/BSGAppHangDetector.m @@ -140,7 +140,7 @@ - (void)detectAppHangs { shouldReportAppHang = NO; } -#if DEBUG +#if defined(DEBUG) && DEBUG if (shouldReportAppHang && bsg_ksmachisBeingTraced()) { bsg_log_debug(@"Ignoring app hang because debugger is attached"); shouldReportAppHang = NO; diff --git a/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_Jailbreak.h b/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_Jailbreak.h index 0d9676998..05e9cb7fe 100644 --- a/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_Jailbreak.h +++ b/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_Jailbreak.h @@ -105,7 +105,7 @@ static inline bool bsg_local_is_insert_libraries_env_var(const char* str) { } \ } while(0) -#elif TARGET_CPU_X86_64 && __GCC_ASM_FLAG_OUTPUTS__ +#elif TARGET_CPU_X86_64 && defined(__GCC_ASM_FLAG_OUTPUTS__) #define BSG_HAS_CUSTOM_SYSCALL 1 // X86_64 3-parameter syscall diff --git a/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m b/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m index 9282ad4fb..e98b3d854 100644 --- a/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m +++ b/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m @@ -418,7 +418,7 @@ + (NSDictionary *)buildSystemInfoStatic { sysInfo[@BSG_KSSystemField_BinaryArch] = [self CPUArchForCPUType:header->cputype subType:header->cpusubtype]; sysInfo[@BSG_KSSystemField_DeviceAppHash] = [self deviceAndAppHash]; -#if TARGET_OS_OSX || TARGET_OS_MACCATALYST || TARGET_OS_SIMULATOR +#if TARGET_OS_OSX || (defined(TARGET_OS_MACCATALYST) && TARGET_OS_MACCATALYST) || TARGET_OS_SIMULATOR // https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment int proc_translated = 0; size_t size = sizeof(proc_translated); diff --git a/Bugsnag/KSCrash/Source/KSCrash/Recording/Sentry/BSG_KSCrashSentry_MachException.c b/Bugsnag/KSCrash/Source/KSCrash/Recording/Sentry/BSG_KSCrashSentry_MachException.c index 850352107..761d81216 100644 --- a/Bugsnag/KSCrash/Source/KSCrash/Recording/Sentry/BSG_KSCrashSentry_MachException.c +++ b/Bugsnag/KSCrash/Source/KSCrash/Recording/Sentry/BSG_KSCrashSentry_MachException.c @@ -46,7 +46,7 @@ #define kThreadPrimary "KSCrash Exception Handler (Primary)" #define kThreadSecondary "KSCrash Exception Handler (Secondary)" -#if __LP64__ +#ifdef __LP64__ #define MACH_ERROR_CODE_MASK 0xFFFFFFFFFFFFFFFF #else #define MACH_ERROR_CODE_MASK 0xFFFFFFFF diff --git a/Bugsnag/KSCrash/Source/KSCrash/Recording/Sentry/BSG_KSCrashSentry_NSException.m b/Bugsnag/KSCrash/Source/KSCrash/Recording/Sentry/BSG_KSCrashSentry_NSException.m index b2f8bed1b..86a05fc92 100644 --- a/Bugsnag/KSCrash/Source/KSCrash/Recording/Sentry/BSG_KSCrashSentry_NSException.m +++ b/Bugsnag/KSCrash/Source/KSCrash/Recording/Sentry/BSG_KSCrashSentry_NSException.m @@ -182,7 +182,7 @@ static void bsg_reportException(id self, SEL _cmd, NSException *exception) { bsg_kscrashsentry_endHandlingCrash(); } -#if TARGET_OS_MACCATALYST +#if defined(TARGET_OS_MACCATALYST) && TARGET_OS_MACCATALYST // Mac Catalyst apps continue to run after an uncaught exception is thrown // while handling a UI event. Our crash sentries should remain installed to // catch any subsequent unhandled exceptions or crashes. diff --git a/Bugsnag/KSCrash/Source/KSCrash/Recording/Tools/BSG_Symbolicate.c b/Bugsnag/KSCrash/Source/KSCrash/Recording/Tools/BSG_Symbolicate.c index 376451957..d5c1cf377 100644 --- a/Bugsnag/KSCrash/Source/KSCrash/Recording/Tools/BSG_Symbolicate.c +++ b/Bugsnag/KSCrash/Source/KSCrash/Recording/Tools/BSG_Symbolicate.c @@ -136,7 +136,7 @@ void bsg_symbolicate(const uintptr_t instruction_addr, struct bsg_symbolicate_re if (leb128_uintptr_decode(&context, data[i], &delta) && delta) { addr += delta; uintptr_t next_func_start = addr; -#if __arm__ +#if defined(__arm__) #define THUMB_INSTRUCTION_TAG 1ul // ld64 sets the least significant bit for thumb instructions, which needs to be // zeroed to recover the original address - see FunctionStartsAtom::encode()