On 14 April 2015 at 02:46, Matthew Knepley <[email protected]> wrote: > On Mon, Apr 13, 2015 at 5:48 PM, Barry Smith <[email protected]> wrote: >> >> >> When I run clang --analyze on PETSc on getting warnings of the type below, >> any idea how to deal with them? Clearly these things are usually not null >> pointers or PETSc would crash everywhere. > > > Lisandro brought this up. > > This is a problem with the analyzer. Anything that uses PetscMallocK() will > be wrong since it can > possibly be NULL. The limitations of static analysis are stark. >
There is a way to silent many of these false positives: 1) First we need to solve the differences between PetscMalloc() and PetscMallocK() regarding zero-size allocations. 2) PetscMalloc1() is by far the most used of all the PetscMallocK() routines. So we should make PetscMalloc1() a direct call to PetscMalloc() (no checks for zero-sized allocs) and modify PetscMalloc() to handle zero-sized allocations by setting the pointer to NULL. These simple changes will remove tons of "null pointer dereference" false positives, and also fix the inconsistent behavior between PetscMalloc() and PetscMallocK(). -- Lisandro Dalcin ============ Research Scientist Computer, Electrical and Mathematical Sciences & Engineering (CEMSE) Numerical Porous Media Center (NumPor) King Abdullah University of Science and Technology (KAUST) http://numpor.kaust.edu.sa/ 4700 King Abdullah University of Science and Technology al-Khawarizmi Bldg (Bldg 1), Office # 4332 Thuwal 23955-6900, Kingdom of Saudi Arabia http://www.kaust.edu.sa Office Phone: +966 12 808-0459
