Errors and warnings detected by LLVM/CLANG/Apple's analyzer

Erik.Buck
Posts: 1
Joined: Tue Dec 09, 2014 12:15 am

Errors and warnings detected by LLVM/CLANG/Apple's analyzer

Post by Erik.Buck »

I searched for relevant terms, LLVM, CLANG, Static Analyzer, and NULL pointer errors. I apologize if I missed this topic in the forum archives.

I am a long time user of Bullet Physics. I have used various versions in programming courses that I teach since at least 2011. I have also used bullet physics in games and tools such as Blender.

Apple's CLANG/LLVM based static analyzer claimed there were a hundred or so serious coding errors in old BulletPhysics versions. Some of the errors such as accessing uninitialized variables and dereferencing NULL pointers cropped up in use. I submitted fixes for many under a different user name that I have now forgotten, or I would still be using it.

Now that we are onto version 3, the number of serious problems detected is down to 32, and troublesome warnings are down to 24. That is great progress. I volunteer to take a stab at fixing the remaining problems over the upcoming holiday break and submit them via Git Hub - unless there is some objection or someone else is already working on the problems.

For example (from the current snapshot in Git Hub):
Line 149 in b3DynamicBvhBroadphase.cpp, Apple's analyzer claims "Called C++ object pointer is null (within a call to resize)".
m_proxies.resize(proxyCapacity);

Line 1127 in btConvexHUll.cpp, Returning null reference (within call to 'operator[]')
memset(&usedIndices[0],0,sizeof(unsigned int)*vcount);

Line 545 of b3PgsJacobiSolver.cpp, Apple's analyzer claims "Access to field 'm_invMAss' results in a dereference of a null pointer..."

b3Scalar countA = body0->m_invMass ? b3Scalar(m_bodyCount[solverBodyA.m_originalBodyIndex]): 1.f;

It is always possible that Apple's static analyzer is wrong, but it has been right enough for me to be concerned.