Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

""NULL check on p after dereference of p","

Issuing an error or warning about this would flood stuff with warnings due to inlining/macros, you name it.

This happens all the time.

Basically, distinguishing between the things that are accidents, and things that are on purpose and expected to be optimized away, is very very very hard.



The warning could be "NULL check after unchecked dereference" with a pragma to disable the warning for macros within an annotated method


The unchecked doesn't add anything that makes it easier, and debugging functions and others rarely check things.

  /* Assumes you have a valid foo */
  int printfoo(struct foo *bar)
  {
  
    /* Print the main part of our foo */
    printf("First field: %d\n", bar->first);
    /* Get the substructure value */
    int foosub = get_foosub(bar);
    printf("Second field: %d\n", bar->second);
  }
   
  /* Doesn't assume you have a valid foo */
  int get_foobsub(struct foo *bar)
  {
     if (bar != NULL)
       return bar->second;
     assert();
  }

In any case, people have spent a long amount of time trying to make warnings like this work without massive false positive rates. It's just not easy.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: