facebook / infer

A static analyzer for Java, C, C++, and Objective-C
http://fbinfer.com/
MIT License
14.89k stars 2.01k forks source link

Null Dereference With Objective-c Class methods call #1615

Closed YLightC closed 2 years ago

YLightC commented 2 years ago
  1. Infer version v1.1.02.
  2. MacOS Big Sur 11.3.1
  3. infer run --keep-going -o ./infer --compilation-database-escaped compile_commands.json
    xxxx.m:96: error: Null Dereference
    pointer `null` is dereferenced by call to `presentToViewController:animated:completion:error:` at line 96, column 9.
    94.         UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:containerViewController];
    95.         nav.modalPresentationStyle = UIModalPresentationFullScreen;
    96.         [VdnUtils presentToViewController:nav
              ^
    97.                                    animated:YES
    98.                                  completion:^{

    This my VdnUtils

    @interface VdnUtils : NSObject
    + (void)presentToViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(void (^__nullable)(void))completion error:(NSError **)error;
    @end

This function will call [VdnUtils presentToViewController: animated: completion: error:]

- (void)createMpaasWithlaunchPage:(id<Page>)page complete:(UpVdnCompleteBlock)complete error:(UpVdnErrorBlock)error
{
    UIViewController *vc = [[InfoViewCotroller alloc] init];;
    BOOL animated = YES;
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    nav.modalPresentationStyle = UIModalPresentationFullScreen;
    [VdnUtils presentToViewController:nav
                                   animated:animated
                                 completion:^{

                                 }
                                      error:nil];
}
YLightC commented 2 years ago

I solved it. It pass error was nil.And this function [VdnUtils presentToViewController: animated: completion: error:] declaration error is **error.And in this function I did this

if (xxx)
{
}  else if (*error != Null) {
}

If pass error is nil, it could be crash, if if (xxx) false.

Thank you for making this tool.