Skip to content

Commit b3a0d03

Browse files
committed
iOs: errors handling added to modelVersion
1 parent 0cce7b4 commit b3a0d03

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/ios/CDVDevice.m

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,22 @@ - (NSString*)modelVersion
3333
#if TARGET_IPHONE_SIMULATOR
3434
NSString* platform = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"];
3535
#else
36-
size_t size;
36+
size_t size = 0;
37+
38+
if(sysctlbyname("hw.machine", NULL, &size, NULL, 0) != 0) {
39+
return nil;
40+
}
3741

38-
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
3942
char* machine = malloc(size);
40-
sysctlbyname("hw.machine", machine, &size, NULL, 0);
43+
if(!machine) {
44+
return nil;
45+
}
46+
47+
if(sysctlbyname("hw.machine", machine, &size, NULL, 0) != 0) {
48+
free(machine);
49+
return nil;
50+
}
51+
4152
NSString* platform = [NSString stringWithUTF8String:machine];
4253
free(machine);
4354
#endif

0 commit comments

Comments
 (0)