[petsc-dev] clang --analyze messages on PETSc

Barry Smith bsmith at mcs.anl.gov
Tue Apr 14 17:54:16 CDT 2015


> On Apr 14, 2015, at 3:33 AM, Lisandro Dalcin <dalcinl at gmail.com> wrote:
> 
> On 14 April 2015 at 02:46, Matthew Knepley <knepley at gmail.com> wrote:
>> On Mon, Apr 13, 2015 at 5:48 PM, Barry Smith <bsmith at mcs.anl.gov> 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,

   But presumably not fix the messages for PetscMalloc2,3,4,...()? So it is really a half-assed fix.

  I also don't understand why it would remove any warnings. Now PetscMalloc() could produce a zero pointer and so clang would still think that the pointer it uses later will be a null pointer deference. Why does moving the PetscMalloc1() handling of zero length to PetscMalloc() remove anything. 

  In fact why have a PetscMalloc() at all? Why not just have PetscMalloc1() call the function pointer and PetscMalloc2() etc call PetscMalloc1().

  Barry


> 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




More information about the petsc-dev mailing list