Skip to content

Commit

Permalink
Fix some compiler warnings in irrlicht (#5144)
Browse files Browse the repository at this point in the history
- Avoid dereferencing null pointer
- Remove some unused variables
  • Loading branch information
nyllet authored Aug 11, 2024
1 parent 427455a commit 386ac8f
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 17 deletions.
2 changes: 0 additions & 2 deletions lib/irrlicht/source/Irrlicht/CGUIContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ void CGUIContextMenu::draw()
// loop through all menu items

rect = AbsoluteRect;
s32 y = AbsoluteRect.UpperLeftCorner.Y;

for (s32 i=0; i<(s32)Items.size(); ++i)
{
Expand All @@ -549,7 +548,6 @@ void CGUIContextMenu::draw()
rect.UpperLeftCorner.Y += 1;
skin->draw2DRectangle(this, skin->getColor(EGDC_3D_HIGH_LIGHT), rect, clip);

y += 10;
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
#endif
#ifdef ANDROID
Android_initDisplayCutout(&TopPadding, &BottomPadding, &LeftPadding, &RightPadding, &InitialOrientation);
#else
(void)InitialOrientation;
#endif
core::stringc sdlversion = "Compiled SDL Version ";
sdlversion += Info.version.major;
Expand Down
6 changes: 0 additions & 6 deletions lib/irrlicht/source/Irrlicht/CMeshManipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,6 @@ IMesh* CMeshManipulator::createForsythOptimizedMesh(const IMesh *mesh) const

// Main algorithm
u32 highest = 0;
u32 drawcalls = 0;
for (;;)
{
if (tc[highest].drawn)
Expand Down Expand Up @@ -1582,7 +1581,6 @@ IMesh* CMeshManipulator::createForsythOptimizedMesh(const IMesh *mesh) const
lru.add(tc[highest].ind[0]);
lru.add(tc[highest].ind[1]);
highest = lru.add(tc[highest].ind[2], true);
drawcalls++;
}

buf->setBoundingBox(mb->getBoundingBox());
Expand All @@ -1605,7 +1603,6 @@ IMesh* CMeshManipulator::createForsythOptimizedMesh(const IMesh *mesh) const

// Main algorithm
u32 highest = 0;
u32 drawcalls = 0;
for (;;)
{
if (tc[highest].drawn)
Expand Down Expand Up @@ -1694,7 +1691,6 @@ IMesh* CMeshManipulator::createForsythOptimizedMesh(const IMesh *mesh) const
lru.add(tc[highest].ind[0]);
lru.add(tc[highest].ind[1]);
highest = lru.add(tc[highest].ind[2]);
drawcalls++;
}

buf->setBoundingBox(mb->getBoundingBox());
Expand All @@ -1718,7 +1714,6 @@ IMesh* CMeshManipulator::createForsythOptimizedMesh(const IMesh *mesh) const

// Main algorithm
u32 highest = 0;
u32 drawcalls = 0;
for (;;)
{
if (tc[highest].drawn)
Expand Down Expand Up @@ -1807,7 +1802,6 @@ IMesh* CMeshManipulator::createForsythOptimizedMesh(const IMesh *mesh) const
lru.add(tc[highest].ind[0]);
lru.add(tc[highest].ind[1]);
highest = lru.add(tc[highest].ind[2]);
drawcalls++;
}

buf->setBoundingBox(mb->getBoundingBox());
Expand Down
5 changes: 3 additions & 2 deletions lib/irrlicht/source/Irrlicht/CNullDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,9 @@ const SLight& CNullDriver::getDynamicLight(u32 idx) const
{
if ( idx < Lights.size() )
return Lights[idx];
else
return *((SLight*)0);
static const SLight defaultLight;
os::Printer::log("Error: CNullDriver::getDynamicLight was invoked with an invalid index.", ELL_ERROR);
return defaultLight;
}


Expand Down
6 changes: 3 additions & 3 deletions lib/irrlicht/source/Irrlicht/COSOperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ namespace irr
{

// constructor linux
COSOperator::COSOperator(const core::stringc& osVersion, IrrlichtDevice* device)
: OperatingSystem(osVersion), IrrDevice(device)
COSOperator::COSOperator(const core::stringc& osVersion, IrrlichtDevice* /*device*/)
: OperatingSystem(osVersion)
{
}


// constructor
COSOperator::COSOperator(const core::stringc& osVersion)
: OperatingSystem(osVersion), IrrDevice(NULL)
: OperatingSystem(osVersion)
{
#ifdef _DEBUG
setDebugName("COSOperator");
Expand Down
1 change: 0 additions & 1 deletion lib/irrlicht/source/Irrlicht/COSOperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class COSOperator : public IOSOperator
private:

core::stringc OperatingSystem;
IrrlichtDevice* IrrDevice;

};

Expand Down
8 changes: 6 additions & 2 deletions lib/irrlicht/source/Irrlicht/CSceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,8 +906,12 @@ const core::aabbox3d<f32>& CSceneManager::getBoundingBox() const
{
_IRR_DEBUG_BREAK_IF(true) // Bounding Box of Scene Manager wanted.

// should never be used.
return *((core::aabbox3d<f32>*)0);
os::Printer::log("Unexpected call to CSceneManager::getBoundingBox()", ELL_ERROR);
// Static default bounding box to return in case this function is called unexpectedly
static const core::aabbox3d<f32> defaultBox;

// Should never be used, but we return a safe reference instead of dereferencing a null pointer.
return defaultBox;
}


Expand Down
2 changes: 1 addition & 1 deletion lib/irrlicht/source/Irrlicht/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ namespace os
//! generates a pseudo random number
f32 Randomizer::frand()
{
return rand()*(1.f/rMax);
return rand()*(1.f/static_cast<f32>(rMax));
}

s32 Randomizer::randMax()
Expand Down

0 comments on commit 386ac8f

Please sign in to comment.