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

use null terminated string for userinfo #591

Merged
merged 3 commits into from
Nov 11, 2024
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
15 changes: 3 additions & 12 deletions Sources/KSCrashRecording/KSCrash.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ - (void)setUserInfo:(NSDictionary *)userInfo
}
}

const char *userInfoCString = userInfoJSON ? [userInfoJSON bytes] : NULL;
kscrash_setUserInfoJSON(userInfoCString);
NSString *userInfoString =
userInfoJSON ? [[NSString alloc] initWithData:userInfoJSON encoding:NSUTF8StringEncoding] : nil;
GLinnik21 marked this conversation as resolved.
Show resolved Hide resolved
kscrash_setUserInfoJSON(userInfoString.UTF8String);
}

- (BOOL)reportsMemoryTerminations
Expand Down Expand Up @@ -320,16 +321,6 @@ -(TYPE)NAME { return kscrashstate_currentState()->NAME; }
#pragma mark - Utility -
// ============================================================================

- (NSMutableData *)nullTerminated:(NSData *)data
{
if (data == nil) {
return NULL;
}
NSMutableData *mutable = [NSMutableData dataWithData:data];
[mutable appendBytes:"\0" length:1];
return mutable;
}

+ (NSError *)errorForInstallErrorCode:(KSCrashInstallErrorCode)errorCode
{
NSString *errorDescription;
Expand Down
51 changes: 51 additions & 0 deletions Tests/KSCrashRecordingTests/KSCrash_Tests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// KSCrash_Tests.m
//
// Created by Aliaksei Nestsiarovich on 11.11.2024.
//
// Copyright (c) 2012 Karl Stenerud. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall remain in place
// in this source code.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#import <XCTest/XCTest.h>

#import "KSCrash.h"

@interface KSCrash_Tests : XCTestCase
@end

@implementation KSCrash_Tests

- (void)testUserInfo
{
NSDictionary *userInfo = @{ @"key1" : @"value1", @"key2" : @123 };
[[KSCrash sharedInstance] setUserInfo:userInfo];

XCTAssertEqualObjects([[KSCrash sharedInstance] userInfo], userInfo);
}

- (void)testUserInfoIfNul
{
[[KSCrash sharedInstance] setUserInfo:nil];

XCTAssertNil([[KSCrash sharedInstance] userInfo]);
}

@end
Loading