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.
92 lines
1.3 KiB
92 lines
1.3 KiB
/*
|
|
* Copyright (c) 2014 - Facebook.
|
|
* All rights reserved.
|
|
*/
|
|
|
|
#import <Foundation/NSObject.h>
|
|
|
|
@interface A : NSObject
|
|
@end
|
|
|
|
|
|
@implementation A {
|
|
|
|
void (^_block_field)(void);
|
|
}
|
|
|
|
|
|
- (void)doSomethingThenCallback:( void(^)(void) ) my_block
|
|
{
|
|
// null dereference, segfault
|
|
my_block();
|
|
|
|
}
|
|
|
|
|
|
- (void) foo {
|
|
|
|
void (^my_block)(void)=^() {};
|
|
my_block = NULL;
|
|
my_block(); // Null deref
|
|
|
|
}
|
|
|
|
|
|
- foo2: ( void(^)(void) ) my_block {
|
|
// ok to call this block!
|
|
if(my_block != nil) {
|
|
my_block();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
- (void) foo3: ( void(^)(void) ) my_block {
|
|
|
|
my_block = NULL;
|
|
my_block(); //Null deref
|
|
|
|
}
|
|
|
|
- (void) foo4: ( void(^)(void) ) my_block_param {
|
|
|
|
void (^my_block)(void)=^() {};
|
|
my_block = NULL;
|
|
my_block_param = my_block;
|
|
my_block_param(); //Null deref
|
|
|
|
}
|
|
|
|
- (void) foo5: ( void(^)(void) ) my_block_param {
|
|
|
|
void (^my_block)(void)=^() {};
|
|
my_block_param = my_block;
|
|
my_block_param(); //No error here
|
|
|
|
}
|
|
|
|
|
|
- (void) foo6: (BOOL)a block_param: ( void (^)(void)) block_param {
|
|
|
|
void (^my_block)(void)=^() {
|
|
if (block_param)
|
|
block_param(); //No error here
|
|
|
|
};
|
|
|
|
if (a){
|
|
[self foo2: ^() {
|
|
my_block(); // No error here
|
|
}];
|
|
}
|
|
|
|
}
|
|
|
|
- (void) foo7 {
|
|
|
|
_block_field(); // Ivar not nullable
|
|
|
|
}
|
|
|
|
@end
|