Commit a87bb3a0 authored by cutealien's avatar cutealien

- Fix a bunch of off-by one errors in irr::core::string in functions...

- Fix a bunch of off-by one errors in irr::core::string in functions equals_substring_ignore_case, findFirst, findFirstChar, findNext, findLast, findLastChar, replace, remove and removeChars. This prevents some potential memory access errors, find functions no longer try to find the \0, replace no longer replaces the \0 and remove no longer tries to remove it (which did remove the last character instead).
- Fix a few new warnings in gcc.



git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4308 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 74d18ec6
Changes in 1.8 (??.??.2011) Changes in 1.8 (??.??.2011)
- Fix a bunch of off-by one errors in irr::core::string in functions equals_substring_ignore_case, findFirst, findFirstChar, findNext, findLast, findLastChar, replace, remove and removeChars.
This prevents some potential memory access errors, find functions no longer try to find the \0, replace no longer replaces the \0 and remove no longer tries to remove it (which did remove the last character instead).
- matrix4::setRotationAxisRadians added - matrix4::setRotationAxisRadians added
- quaternion conversions to and from matrix4 no longer invert rotations. - quaternion conversions to and from matrix4 no longer invert rotations.
......
...@@ -501,7 +501,7 @@ public: ...@@ -501,7 +501,7 @@ public:
//! Makes the string lower case. //! Makes the string lower case.
string<T,TAlloc>& make_lower() string<T,TAlloc>& make_lower()
{ {
for (u32 i=0; i<used; ++i) for (u32 i=0; array[i]; ++i)
array[i] = locale_lower ( array[i] ); array[i] = locale_lower ( array[i] );
return *this; return *this;
} }
...@@ -510,7 +510,7 @@ public: ...@@ -510,7 +510,7 @@ public:
//! Makes the string upper case. //! Makes the string upper case.
string<T,TAlloc>& make_upper() string<T,TAlloc>& make_upper()
{ {
for (u32 i=0; i<used; ++i) for (u32 i=0; array[i]; ++i)
array[i] = locale_upper ( array[i] ); array[i] = locale_upper ( array[i] );
return *this; return *this;
} }
...@@ -534,7 +534,7 @@ public: ...@@ -534,7 +534,7 @@ public:
\return True if the strings are equal ignoring case. */ \return True if the strings are equal ignoring case. */
bool equals_substring_ignore_case(const string<T,TAlloc>&other, const s32 sourcePos = 0 ) const bool equals_substring_ignore_case(const string<T,TAlloc>&other, const s32 sourcePos = 0 ) const
{ {
if ( (u32) sourcePos > used ) if ( (u32) sourcePos >= used )
return false; return false;
u32 i; u32 i;
...@@ -717,7 +717,7 @@ public: ...@@ -717,7 +717,7 @@ public:
or -1 if not found. */ or -1 if not found. */
s32 findFirst(T c) const s32 findFirst(T c) const
{ {
for (u32 i=0; i<used; ++i) for (u32 i=0; i<used-1; ++i)
if (array[i] == c) if (array[i] == c)
return i; return i;
...@@ -736,7 +736,7 @@ public: ...@@ -736,7 +736,7 @@ public:
if (!c || !count) if (!c || !count)
return -1; return -1;
for (u32 i=0; i<used; ++i) for (u32 i=0; i<used-1; ++i)
for (u32 j=0; j<count; ++j) for (u32 j=0; j<count; ++j)
if (array[i] == c[j]) if (array[i] == c[j])
return i; return i;
...@@ -806,7 +806,7 @@ public: ...@@ -806,7 +806,7 @@ public:
or -1 if not found. */ or -1 if not found. */
s32 findNext(T c, u32 startPos) const s32 findNext(T c, u32 startPos) const
{ {
for (u32 i=startPos; i<used; ++i) for (u32 i=startPos; i<used-1; ++i)
if (array[i] == c) if (array[i] == c)
return i; return i;
...@@ -821,7 +821,7 @@ public: ...@@ -821,7 +821,7 @@ public:
or -1 if not found. */ or -1 if not found. */
s32 findLast(T c, s32 start = -1) const s32 findLast(T c, s32 start = -1) const
{ {
start = core::clamp ( start < 0 ? (s32)(used) - 1 : start, 0, (s32)(used) - 1 ); start = core::clamp ( start < 0 ? (s32)(used) - 2 : start, 0, (s32)(used) - 2 );
for (s32 i=start; i>=0; --i) for (s32 i=start; i>=0; --i)
if (array[i] == c) if (array[i] == c)
return i; return i;
...@@ -841,7 +841,7 @@ public: ...@@ -841,7 +841,7 @@ public:
if (!c || !count) if (!c || !count)
return -1; return -1;
for (s32 i=used-1; i>=0; --i) for (s32 i=(s32)used-2; i>=0; --i)
for (u32 j=0; j<count; ++j) for (u32 j=0; j<count; ++j)
if (array[i] == c[j]) if (array[i] == c[j])
return i; return i;
...@@ -1006,7 +1006,7 @@ public: ...@@ -1006,7 +1006,7 @@ public:
\param replaceWith Character replacing the old one. */ \param replaceWith Character replacing the old one. */
string<T,TAlloc>& replace(T toReplace, T replaceWith) string<T,TAlloc>& replace(T toReplace, T replaceWith)
{ {
for (u32 i=0; i<used; ++i) for (u32 i=0; i<used-1; ++i)
if (array[i] == toReplace) if (array[i] == toReplace)
array[i] = replaceWith; array[i] = replaceWith;
return *this; return *this;
...@@ -1128,7 +1128,7 @@ public: ...@@ -1128,7 +1128,7 @@ public:
{ {
u32 pos = 0; u32 pos = 0;
u32 found = 0; u32 found = 0;
for (u32 i=0; i<used; ++i) for (u32 i=0; i<used-1; ++i)
{ {
if (array[i] == c) if (array[i] == c)
{ {
...@@ -1153,7 +1153,7 @@ public: ...@@ -1153,7 +1153,7 @@ public:
return *this; return *this;
u32 pos = 0; u32 pos = 0;
u32 found = 0; u32 found = 0;
for (u32 i=0; i<used; ++i) for (u32 i=0; i<used-1; ++i)
{ {
u32 j = 0; u32 j = 0;
while (j < size) while (j < size)
...@@ -1186,7 +1186,7 @@ public: ...@@ -1186,7 +1186,7 @@ public:
u32 pos = 0; u32 pos = 0;
u32 found = 0; u32 found = 0;
for (u32 i=0; i<used; ++i) for (u32 i=0; i<used-1; ++i)
{ {
// Don't use characters.findFirst as it finds the \0, // Don't use characters.findFirst as it finds the \0,
// causing used to become incorrect. // causing used to become incorrect.
......
...@@ -617,6 +617,8 @@ void CColladaMeshWriter::writeNodeLights(irr::scene::ISceneNode * node) ...@@ -617,6 +617,8 @@ void CColladaMeshWriter::writeNodeLights(irr::scene::ISceneNode * node)
Writer->writeClosingTag(L"directional"); Writer->writeClosingTag(L"directional");
Writer->writeLineBreak(); Writer->writeLineBreak();
break; break;
default:
break;
} }
Writer->writeClosingTag(L"technique_common"); Writer->writeClosingTag(L"technique_common");
......
...@@ -69,6 +69,8 @@ void CLightSceneNode::render() ...@@ -69,6 +69,8 @@ void CLightSceneNode::render()
LightData.Direction * LightData.Radius, LightData.Direction * LightData.Radius,
LightData.DiffuseColor.toSColor()); LightData.DiffuseColor.toSColor());
break; break;
default:
break;
} }
} }
......
...@@ -3448,6 +3448,8 @@ void COpenGLDriver::assignHardwareLight(u32 lightIndex) ...@@ -3448,6 +3448,8 @@ void COpenGLDriver::assignHardwareLight(u32 lightIndex)
glLightf(lidx, GL_SPOT_EXPONENT, 0.0f); glLightf(lidx, GL_SPOT_EXPONENT, 0.0f);
glLightf(lidx, GL_SPOT_CUTOFF, 180.0f); glLightf(lidx, GL_SPOT_CUTOFF, 180.0f);
break; break;
default:
break;
} }
// set diffuse color // set diffuse color
......
...@@ -1942,6 +1942,8 @@ s32 CBurningVideoDriver::addDynamicLight(const SLight& dl) ...@@ -1942,6 +1942,8 @@ s32 CBurningVideoDriver::addDynamicLight(const SLight& dl)
l.linearAttenuation = 1.f / dl.Radius; l.linearAttenuation = 1.f / dl.Radius;
l.quadraticAttenuation = dl.Attenuation.Z; l.quadraticAttenuation = dl.Attenuation.Z;
break;
default:
break; break;
} }
...@@ -2162,6 +2164,8 @@ void CBurningVideoDriver::lightVertex ( s4DVertex *dest, u32 vertexargb ) ...@@ -2162,6 +2164,8 @@ void CBurningVideoDriver::lightVertex ( s4DVertex *dest, u32 vertexargb )
// diffuse component // diffuse component
diffuse.mulAdd ( light.DiffuseColor, dot ); diffuse.mulAdd ( light.DiffuseColor, dot );
break; break;
default:
break;
} }
} }
......
...@@ -180,6 +180,104 @@ bool testAppendStringc() ...@@ -180,6 +180,104 @@ bool testAppendStringc()
return true; return true;
} }
bool testLowerUpper()
{
irr::core::array <irr::core::stringc> stringsOrig, targetLower, targetUpper;
stringsOrig.push_back("abc");
targetLower.push_back("abc");
targetUpper.push_back("ABC");
stringsOrig.push_back("ABC");
targetLower.push_back("abc");
targetUpper.push_back("ABC");
stringsOrig.push_back("Abc");
targetLower.push_back("abc");
targetUpper.push_back("ABC");
stringsOrig.push_back("aBBc");
targetLower.push_back("abbc");
targetUpper.push_back("ABBC");
stringsOrig.push_back("abC");
targetLower.push_back("abc");
targetUpper.push_back("ABC");
stringsOrig.push_back("");
targetLower.push_back("");
targetUpper.push_back("");
/* TODO: those are not supported so far
stringsOrig.push_back("ßäöü");
targetLower.push_back("ßäöü");
targetUpper.push_back("ßÄÖÜ");
stringsOrig.push_back("ßÄÖÜ");
targetLower.push_back("ßäöü");
targetUpper.push_back("ßÄÖÜ");
*/
for ( irr::u32 i=0; i<stringsOrig.size(); ++i )
{
irr::core::stringc c = stringsOrig[i];
c.make_lower();
if ( c != targetLower[i] )
{
logTestString("make_lower for stringc failed in test %d %s\n", i, stringsOrig[i].c_str());
return false;
}
c = stringsOrig[i];
c.make_upper();
if ( c != targetUpper[i] )
{
logTestString("make_upper for stringc failed in test %d %s %s\n", i, stringsOrig[i].c_str(), c.c_str());
return false;
}
irr::core::stringw w = irr::core::stringw(stringsOrig[i]);
c.make_lower();
if ( c != irr::core::stringw(targetLower[i]) )
{
logTestString("make_lower for stringw failed in test %d %s\n", i, stringsOrig[i].c_str());
return false;
}
c = irr::core::stringw(stringsOrig[i]);
c.make_upper();
if ( c != irr::core::stringw(targetUpper[i]) )
{
logTestString("make_upper for stringw failed in test %d %s\n", i, stringsOrig[i].c_str());
return false;
}
}
return true;
}
bool testFindFunctions()
{
irr::core::stringc dot(".");
irr::s32 p = dot.findFirst(0);
if ( p >= 0 )
return false;
irr::core::stringc empty("");
p = empty.findLastCharNotInList("x",1);
if ( p >= 0 )
return false;
p = empty.findLast('x');
if ( p >= 0 )
return false;
p = dot.findLast('.');
if ( p != 0 )
return false;
p = empty.findLastChar("ab", 2);
if ( p >= 0 )
return false;
p = dot.findLastChar("-.", 2);
if ( p != 0 )
return false;
return true;
}
// Test the functionality of irrString // Test the functionality of irrString
/** Validation is done with assert_log() against expected results. */ /** Validation is done with assert_log() against expected results. */
...@@ -243,6 +341,12 @@ bool testIrrString(void) ...@@ -243,6 +341,12 @@ bool testIrrString(void)
logTestString("test replace\n"); logTestString("test replace\n");
allExpected &= testReplace(); allExpected &= testReplace();
logTestString("test make_lower and make_uppers\n");
allExpected &= testLowerUpper();
logTestString("test find functions\n");
allExpected &= testFindFunctions();
if(allExpected) if(allExpected)
logTestString("\nAll tests passed\n"); logTestString("\nAll tests passed\n");
else else
......
Tests finished. 1 test of 1 passed. Tests finished. 1 test of 1 passed.
Compiled as DEBUG Compiled as DEBUG
Test suite pass at GMT Sat Jul 7 10:28:50 2012 Test suite pass at GMT Thu Sep 6 19:39:44 2012
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment