Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLAT-9362] fix for data race and nullability issues #1515

Merged
merged 3 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [pull_request]
jobs:

analyze:
runs-on: macos-latest
runs-on: macos-11
env:
# Infer 1.0.1 cannot parse the iOS 15 SDK headers
DEVELOPER_DIR: /Applications/Xcode_12.5.1.app
Expand All @@ -23,7 +23,7 @@ jobs:
run: make oclint

danger:
runs-on: macos-latest
runs-on: macos-11
steps:
- name: Checkout target branch
uses: actions/checkout@v2
Expand Down
7 changes: 4 additions & 3 deletions Bugsnag/Helpers/BSGRunContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
atomic_store((_Atomic(typeof(field)) *)&field, newValue_); \
} while (0)


#pragma mark Forward declarations

static uint64_t GetBootTime(void);
Expand Down Expand Up @@ -342,9 +341,11 @@ void BSGRunContextUpdateTimestamp() {
}

static void UpdateHostMemory() {
static mach_port_t host;
static _Atomic mach_port_t host_atomic = 0;
mach_port_t host = atomic_load(&host_atomic);
if (!host) {
host = mach_host_self();
atomic_store(&host_atomic, host);
}

vm_statistics_data_t host_vm;
Expand All @@ -357,7 +358,7 @@ static void UpdateHostMemory() {
}

size_t hostMemoryFree = host_vm.free_count * vm_kernel_page_size;
ATOMIC_SET(bsg_runContext->hostMemoryFree, hostMemoryFree);
bsg_runContext->hostMemoryFree = hostMemoryFree;
}

static void UpdateTaskMemory() {
Expand Down
7 changes: 5 additions & 2 deletions Bugsnag/Helpers/BSGSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ NS_ASSUME_NONNULL_BEGIN
@param input a dictionary
@return a new dictionary
*/
NSMutableDictionary * BSGSanitizeDict(NSDictionary *input);
NSMutableDictionary *BSGSanitizeDict(NSDictionary * input);

NSMutableDictionary *_Nullable BSGSanitizePossibleDict(NSDictionary *_Nullable input);

/**
Cleans the object, including nested dictionary and array values
Expand All @@ -25,7 +27,8 @@ typedef struct _BSGTruncateContext {
NSUInteger length;
} BSGTruncateContext;

NSString * BSGTruncateString(BSGTruncateContext *context, NSString *_Nullable string);
NSString * BSGTruncateString(BSGTruncateContext *context, NSString * string);
NSString *_Nullable BSGTruncatePossibleString(BSGTruncateContext *context, NSString *_Nullable string);

id BSGTruncateStrings(BSGTruncateContext *context, id object);

Expand Down
12 changes: 10 additions & 2 deletions Bugsnag/Helpers/BSGSerialization.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ id BSGSanitizeObject(id obj) {
return nil;
}

NSMutableDictionary * BSGSanitizeDict(NSDictionary *input) {
NSMutableDictionary * BSGSanitizePossibleDict(NSDictionary *input) {
if (![input isKindOfClass:[NSDictionary class]]) {
return nil;
}
return BSGSanitizeDict(input);
}

NSMutableDictionary * BSGSanitizeDict(NSDictionary *input) {
__block NSMutableDictionary *output =
[NSMutableDictionary dictionaryWithCapacity:[input count]];
[input enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj,
Expand All @@ -47,10 +51,14 @@ id BSGSanitizeObject(id obj) {
return output;
}

NSString * BSGTruncateString(BSGTruncateContext *context, NSString *string) {
NSString * BSGTruncatePossibleString(BSGTruncateContext *context, NSString *string) {
if (![string isKindOfClass:[NSString class]]) {
return nil;
}
return BSGTruncateString(context, string);
}

NSString * BSGTruncateString(BSGTruncateContext *context, NSString *string) {
const NSUInteger inputLength = string.length;
if (inputLength <= context->maxLength) return string;
// Prevent chopping in the middle of a composed character sequence
Expand Down
6 changes: 3 additions & 3 deletions Bugsnag/Payload/BugsnagEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -729,12 +729,12 @@ - (void)truncateStrings:(NSUInteger)maxLength {
};

if (self.context) {
self.context = BSGTruncateString(&context, self.context);
self.context = BSGTruncatePossibleString(&context, self.context);
}

for (BugsnagError *error in self.errors) {
error.errorClass = BSGTruncateString(&context, error.errorClass);
error.errorMessage = BSGTruncateString(&context, error.errorMessage);
error.errorClass = BSGTruncatePossibleString(&context, error.errorClass);
error.errorMessage = BSGTruncatePossibleString(&context, error.errorMessage);
}

for (BugsnagBreadcrumb *breadcrumb in self.breadcrumbs) {
Expand Down
8 changes: 7 additions & 1 deletion Tests/BugsnagTests/BugsnagCollectionsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ - (void)testDstEmpty {

- (void)testDstNil {
id src = @{@"a": @"one"};
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
XCTAssertEqualObjects(src, BSGDictMerge(src, nil), @"should copy");
#pragma clang diagnostic pop
}

- (void)testSrcDict {
Expand All @@ -74,8 +77,11 @@ - (void)testSrcDstDict {
// MARK: BSGJSONDictionary

- (void)testBSGJSONDictionary {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
XCTAssertNil(BSGJSONDictionary(nil));

#pragma clang diagnostic pop

id validDictionary = @{
@"name": @"foobar",
@"count": @1,
Expand Down