iNavFlight / inav

INAV: Navigation-enabled flight control software
https://inavflight.github.io
GNU General Public License v3.0
3.08k stars 1.46k forks source link

Remove unnecessary null pointer checks #3780

Closed elfring closed 6 years ago

elfring commented 6 years ago

An extra null pointer check is not needed in functions like the following.

digitalentity commented 6 years ago

Removing NULL pointer check there creates a potential NULL-pointer dereference bug. I strongly advise against removing there kinds of checks.

digitalentity commented 6 years ago

Moreover, those functions are not used by INAV and are optimized out by GCC

elfring commented 6 years ago

A POSIX compliant free() function will return immediately if a null pointer was passed. Thus I do not see a need to repeat such a sanity check.

digitalentity commented 6 years ago

If you would read the code you'll notice that a point is dereferenced first and then freed:

  /* DeInit  physical Interface components */
  if(pdev->pClassData != NULL)
  {
   ((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->DeInit(0);
    USBD_free(pdev->pClassData);
    pdev->pClassData = NULL;
  }

Regardless, we don't have dynamic memory allocation in INAV, these functions are not used and they are in a 3rd party library which may (and will) be updated eventually (discarding the fixes).