Skip to content

Commit

Permalink
fix some msan (memory sanitizer) issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Erwin Coumans committed May 12, 2021
1 parent 092b7bc commit 92fb2db
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions Extras/Serialize/BulletFileLoader/bFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ bFile::bFile(const char *filename, const char headerString[7])
fseek(fp, 0L, SEEK_SET);

mFileBuffer = (char *)malloc(mFileLen + 1);
memset(mFileBuffer, 0, mFileLen+1);
size_t bytesRead;
bytesRead = fread(mFileBuffer, mFileLen, 1, fp);

Expand Down
1 change: 1 addition & 0 deletions Extras/Serialize/BulletFileLoader/btBulletFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ void btBulletFile::parse(int verboseMode)
if (m_DnaCopy)
delete m_DnaCopy;
m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen64, 16);
memset(m_DnaCopy, 0, sBulletDNAlen64);
memcpy(m_DnaCopy, sBulletDNAstr64, sBulletDNAlen64);
parseInternal(verboseMode, m_DnaCopy, sBulletDNAlen64);
}
Expand Down
3 changes: 3 additions & 0 deletions examples/Utils/b3BulletDefaultFileIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "b3ResourcePath.h"

#include <stdio.h>
#include <string.h>

#define B3_FILEIO_MAX_FILES 1024

struct b3BulletDefaultFileIO : public CommonFileIOInterface
Expand Down Expand Up @@ -155,6 +157,7 @@ struct b3BulletDefaultFileIO : public CommonFileIOInterface
FILE* f = m_fileHandles[fileHandle];
if (f)
{
memset(destBuffer, 0, numBytes);
char* txt = ::fgets(destBuffer, numBytes, m_fileHandles[fileHandle]);
for (int i=0;i<numBytes;i++)
{
Expand Down
2 changes: 0 additions & 2 deletions src/BulletCollision/CollisionDispatch/btManifoldResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,11 @@ btManifoldResult::btManifoldResult(const btCollisionObjectWrapper* body0Wrap, co
: m_manifoldPtr(0),
m_body0Wrap(body0Wrap),
m_body1Wrap(body1Wrap)
#ifdef DEBUG_PART_INDEX
,
m_partId0(-1),
m_partId1(-1),
m_index0(-1),
m_index1(-1)
#endif //DEBUG_PART_INDEX
,
m_closestPointDistanceThreshold(0)
{
Expand Down
10 changes: 9 additions & 1 deletion src/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,17 @@ class btManifoldPoint
btScalar distance) : m_localPointA(pointA),
m_localPointB(pointB),
m_normalWorldOnB(normal),
m_positionWorldOnB(0,0,0),
m_positionWorldOnA(0,0,0),
m_distance1(distance),
m_combinedFriction(btScalar(0.)),
m_combinedRollingFriction(btScalar(0.)),
m_combinedSpinningFriction(btScalar(0.)),
m_combinedRestitution(btScalar(0.)),
m_partId0(-1),
m_partId1(-1),
m_index0(-1),
m_index1(-1),
m_userPersistentData(0),
m_contactPointFlags(0),
m_appliedImpulse(0.f),
Expand All @@ -88,7 +94,9 @@ class btManifoldPoint
m_contactCFM(0.f),
m_contactERP(0.f),
m_frictionCFM(0.f),
m_lifeTime(0)
m_lifeTime(0),
m_lateralFrictionDir1(0,0,0),
m_lateralFrictionDir2(0,0,0)
{
}

Expand Down
7 changes: 6 additions & 1 deletion src/LinearMath/btAlignedAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ subject to the following restrictions:
*/

#include "btAlignedAllocator.h"
#include <string.h>

#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
int gNumAlignedAllocs = 0;
Expand All @@ -23,7 +24,9 @@ int gTotalBytesAlignedAllocs = 0; //detect memory leaks

static void *btAllocDefault(size_t size)
{
return malloc(size);
char* data = (char*) malloc(size);
memset(data,0,size);//keep msan happy
return data;
}

static void btFreeDefault(void *ptr)
Expand Down Expand Up @@ -73,6 +76,8 @@ static inline void *btAlignedAllocDefault(size_t size, int alignment)
{
ret = (void *)(real);
}
//keep msan happy
memset((char*) ret, 0, size);
return (ret);
}

Expand Down

0 comments on commit 92fb2db

Please sign in to comment.