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.
63 lines
1001 B
63 lines
1001 B
/*
|
|
* Copyright (c) 2014 - Facebook.
|
|
* All rights reserved.
|
|
*/
|
|
|
|
#import <Foundation/NSObject.h>
|
|
|
|
@interface Fraction : NSObject {
|
|
int numerator;
|
|
int denominator;
|
|
}
|
|
|
|
- (void)setNumerator:(int)n;
|
|
- (void)setDenominator:(int)d;
|
|
|
|
- (int)getNumerator;
|
|
- (int)getDenominator;
|
|
@end
|
|
|
|
@implementation Fraction
|
|
|
|
- (void)setNumerator:(int)n {
|
|
numerator = n;
|
|
}
|
|
|
|
- (void)setDenominator:(int)d {
|
|
denominator = d;
|
|
}
|
|
|
|
- (int)getNumerator {
|
|
return numerator;
|
|
}
|
|
|
|
- (int)getDenominator {
|
|
return denominator;
|
|
}
|
|
@end
|
|
|
|
|
|
Fraction *Fraction_create() {
|
|
Fraction *f = NULL;
|
|
return f;
|
|
}
|
|
|
|
int null_deref_objc_class() {
|
|
Fraction *fraction = Fraction_create();
|
|
[fraction setNumerator: 5];
|
|
return 0;
|
|
}
|
|
|
|
void test_virtual_call() {
|
|
id *fraction = [Fraction alloc];
|
|
// virtual call: the type of fraction is obtained from the allocation
|
|
[fraction setNumerator: 5];
|
|
if ([fraction getNumerator] != 4) {
|
|
// unreachable
|
|
int *x = NULL;
|
|
*x = 0;
|
|
}
|
|
[fraction release];
|
|
}
|
|
|