You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
4.7 KiB
145 lines
4.7 KiB
10 years ago
|
/*
|
||
6 years ago
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||
9 years ago
|
*
|
||
7 years ago
|
* This source code is licensed under the MIT license found in the
|
||
|
* LICENSE file in the root directory of this source tree.
|
||
9 years ago
|
*/
|
||
10 years ago
|
|
||
|
#import <Foundation/Foundation.h>
|
||
|
|
||
|
void update_dict_with_null() {
|
||
9 years ago
|
NSMutableDictionary* mDict =
|
||
|
[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Matt",
|
||
|
@"firstName",
|
||
|
@"Galloway",
|
||
|
@"lastName",
|
||
|
@28,
|
||
|
@"age",
|
||
|
nil];
|
||
|
mDict[@"firstName"] = nil;
|
||
10 years ago
|
}
|
||
|
|
||
|
void update_dict_with_key_null() {
|
||
9 years ago
|
NSMutableDictionary* mDict =
|
||
|
[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Matt",
|
||
|
@"firstName",
|
||
|
@"Galloway",
|
||
|
@"lastName",
|
||
|
@28,
|
||
|
@"age",
|
||
|
nil];
|
||
|
id key = nil;
|
||
|
mDict[key] = @"Dulma";
|
||
10 years ago
|
}
|
||
|
|
||
|
void update_dict_without_null() {
|
||
9 years ago
|
NSMutableDictionary* mDict =
|
||
|
[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Matt",
|
||
|
@"firstName",
|
||
|
@"Galloway",
|
||
|
@"lastName",
|
||
|
@28,
|
||
|
@"age",
|
||
|
nil];
|
||
|
mDict[@"firstName"] = @"Dulma";
|
||
10 years ago
|
}
|
||
|
|
||
|
void update_array_with_null() {
|
||
9 years ago
|
NSMutableArray* array =
|
||
|
[NSMutableArray arrayWithObjects:@"Dulma", @"Rodriguez", nil];
|
||
|
NSUInteger idx = 0;
|
||
|
id newObject = nil;
|
||
|
array[idx] = newObject;
|
||
10 years ago
|
}
|
||
|
|
||
|
void update_array_without_null() {
|
||
9 years ago
|
NSMutableArray* array =
|
||
|
[NSMutableArray arrayWithObjects:@"Dulma", @"Rodriguez", nil];
|
||
|
NSUInteger idx = 0;
|
||
|
id newObject = @"Dino";
|
||
|
array[idx] = newObject;
|
||
10 years ago
|
}
|
||
|
|
||
|
void add_nil_to_array() {
|
||
9 years ago
|
NSMutableArray* array =
|
||
|
[NSMutableArray arrayWithObjects:@"Dulma", @"Rodriguez", nil];
|
||
|
id str = nil;
|
||
|
[array addObject:str];
|
||
10 years ago
|
}
|
||
|
|
||
|
void insert_nil_in_array() {
|
||
9 years ago
|
NSMutableArray* array =
|
||
|
[NSMutableArray arrayWithObjects:@"Dulma", @"Rodriguez", nil];
|
||
|
id str = nil;
|
||
|
[array insertObject:str atIndex:0];
|
||
10 years ago
|
}
|
||
|
|
||
|
void add_nil_in_dict() {
|
||
9 years ago
|
NSMutableDictionary* mDict =
|
||
|
[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Matt",
|
||
|
@"firstName",
|
||
|
@"Galloway",
|
||
|
@"lastName",
|
||
|
@28,
|
||
|
@"age",
|
||
|
nil];
|
||
|
id str = nil;
|
||
|
[mDict setObject:str forKey:@"firstName"];
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
void no_npe_for_undef_values(NSDictionary* response) {
|
||
|
NSMutableDictionary* fileInfo = [response mutableCopy];
|
||
|
fileInfo[@"type"] = @"BLA";
|
||
|
NSMutableDictionary* d = [NSMutableDictionary dictionary];
|
||
|
d[@"fds"] = fileInfo;
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
|
void nullable_NSDictionary_objectForKey(NSDictionary* dict, NSObject* key) {
|
||
|
if (key != nil) {
|
||
|
// check objectForKey may return nil for non-nil key
|
||
|
if ([dict objectForKey:key] == nil) {
|
||
|
char _ = *(char*)nil;
|
||
|
} // report
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void strict_NSDictionary_objectForKey(NSDictionary* dict) {
|
||
|
// check objectForKey returns nil for nil key
|
||
|
if ([dict objectForKey:nil] != nil) {
|
||
|
char _ = *(char*)nil;
|
||
|
} // no report
|
||
|
}
|
||
|
|
||
|
void nullable_NSDictionary_objectForKeyedSubscript(NSDictionary* dict,
|
||
|
NSObject* key) {
|
||
|
if (key != nil) {
|
||
|
// check objectForKey may return nil for non-nil key
|
||
|
if (dict[key] == nil) {
|
||
|
char _ = *(char*)nil;
|
||
|
} // report
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void strict_NSDictionary_objectForKeyedSubscript(NSDictionary* dict) {
|
||
|
// check objectForKey returns nil for nil key
|
||
|
if (dict[nil] != nil) {
|
||
|
char _ = *(char*)nil;
|
||
|
} // no report
|
||
|
}
|
||
|
|
||
|
void nullable_NSMapTable_objectForKey(NSMapTable* map, NSObject* key) {
|
||
|
if (key != nil) {
|
||
|
// check objectForKey may return nil for non-nil key
|
||
|
if ([map objectForKey:key] == nil) {
|
||
|
char _ = *(char*)nil;
|
||
|
} // report
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void strict_NSMapTable_objectForKey(NSMapTable* map) {
|
||
|
// check objectForKey returns nil for nil key
|
||
|
if ([map objectForKey:nil] != nil) {
|
||
|
char _ = *(char*)nil;
|
||
|
} // no report
|
||
|
}
|