From 71b27eba677428ef177c15bb133705cbb35511f1 Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Thu, 15 Oct 2015 12:07:18 -0500 Subject: [PATCH 1/5] TODO: make this a warning for now...until then need to find out what's causing exteriorAppearanceTemplate to be a null pointer now --- engine/shared/library/sharedFoundation/src/shared/Fatal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/shared/library/sharedFoundation/src/shared/Fatal.h b/engine/shared/library/sharedFoundation/src/shared/Fatal.h index aa25bd48..f33eb5ac 100644 --- a/engine/shared/library/sharedFoundation/src/shared/Fatal.h +++ b/engine/shared/library/sharedFoundation/src/shared/Fatal.h @@ -68,7 +68,7 @@ void SetWarningCallback(WarningCallback); template inline T *NonNull(T *pointer, const char *name) { - FATAL(!pointer, ("%s pointer is null", name)); + WARNING(!pointer, ("%s pointer is null", name)); return pointer; } From ed676cc18cc5242b5f8ee6edf4f060ed71b538d6 Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Fri, 16 Oct 2015 20:57:53 -0500 Subject: [PATCH 2/5] it is undefined operation if these are null anyway... and the compiler doesn't like them because of null pointers, so...bye --- .../src/shared/core/ServerWorld.cpp | 34 ++++++------------- .../src/shared/object/AlterScheduler.cpp | 4 +-- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/engine/server/library/serverGame/src/shared/core/ServerWorld.cpp b/engine/server/library/serverGame/src/shared/core/ServerWorld.cpp index a8d33802..9b94409a 100644 --- a/engine/server/library/serverGame/src/shared/core/ServerWorld.cpp +++ b/engine/server/library/serverGame/src/shared/core/ServerWorld.cpp @@ -199,18 +199,11 @@ void compare_results_int( std::set &results, std::setgetOwner(); - if ( &volumeOwner == NULL ) - { - LOG("SphereGrid", ("Ack null owner!")); - } - else - { - const Object* pob = getContainingPobForObjectInWorld(volume->getOwner()); - Sphere const &localSphere = volumeOwner.getLocalSphere(); - Sphere world(volumeOwner.getTransform_o2w().rotateTranslate_l2p(localSphere.getCenter()), volume->getRadius()); - Vector c=world.getCenter(); - LOG("SphereGrid",(" (%f %f %f) %f POB = %p DIST=%f",c.x,c.y,c.z,world.getRadius(),pob, c.magnitudeBetween(v) )); - } + const Object* pob = getContainingPobForObjectInWorld(volume->getOwner()); + Sphere const &localSphere = volumeOwner.getLocalSphere(); + Sphere world(volumeOwner.getTransform_o2w().rotateTranslate_l2p(localSphere.getCenter()), volume->getRadius()); + Vector c=world.getCenter(); + LOG("SphereGrid",(" (%f %f %f) %f POB = %p DIST=%f",c.x,c.y,c.z,world.getRadius(),pob, c.magnitudeBetween(v) )); } LOG("SphereGrid", ("------------------ Grid Results %d ------------------",results2.size())); @@ -218,18 +211,11 @@ void compare_results_int( std::set &results, std::setgetOwner(); - if ( &volumeOwner == NULL ) - { - LOG("SphereGrid", ("shit null owner.")); - } - else - { - const Object* pob = getContainingPobForObjectInWorld(volume->getOwner()); - Sphere const &localSphere = volumeOwner.getLocalSphere(); - Sphere world(volumeOwner.getTransform_o2w().rotateTranslate_l2p(localSphere.getCenter()), volume->getRadius()); // o2p or o2w - Vector c=world.getCenter(); - LOG("SphereGrid",(" (%f %f %f) %f POB = %p DIST=%f",c.x,c.y,c.z,world.getRadius(),pob, c.magnitudeBetween(v) )); - } + const Object* pob = getContainingPobForObjectInWorld(volume->getOwner()); + Sphere const &localSphere = volumeOwner.getLocalSphere(); + Sphere world(volumeOwner.getTransform_o2w().rotateTranslate_l2p(localSphere.getCenter()), volume->getRadius()); // o2p or o2w + Vector c=world.getCenter(); + LOG("SphereGrid",(" (%f %f %f) %f POB = %p DIST=%f",c.x,c.y,c.z,world.getRadius(),pob, c.magnitudeBetween(v) )); } DEBUG_FATAL(true,("FATAL: SphereGrid failed to match SphereTree result set.")); diff --git a/engine/shared/library/sharedObject/src/shared/object/AlterScheduler.cpp b/engine/shared/library/sharedObject/src/shared/object/AlterScheduler.cpp index 9ae447a4..e09b9c37 100644 --- a/engine/shared/library/sharedObject/src/shared/object/AlterScheduler.cpp +++ b/engine/shared/library/sharedObject/src/shared/object/AlterScheduler.cpp @@ -1184,7 +1184,7 @@ void AlterScheduler::moveObjectsFromAlterNextFrameListToAlterNowList(int schedul { PROFILER_AUTO_BLOCK_DEFINE("copy next frame"); - if (s_alterNextFrameListFirst != NULL) { + //if (s_alterNextFrameListFirst != NULL) { for (Object *object = s_alterNextFrameListFirst[schedulePhaseIndex]->getNextFromAlterNextFrameList(); object != NULL; ) { //-- Add object to alter now list. This removes the object from the alter next frame list. @@ -1203,7 +1203,7 @@ void AlterScheduler::moveObjectsFromAlterNextFrameListToAlterNowList(int schedul //-- Increment loop. object = nextObject; } - } + //} } } From 46316f28fb6b8c5fc1f93ea01945b2bfc37ad759 Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Fri, 16 Oct 2015 21:34:49 -0500 Subject: [PATCH 3/5] another one --- .../library/serverGame/src/shared/object/CreatureObject.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/server/library/serverGame/src/shared/object/CreatureObject.cpp b/engine/server/library/serverGame/src/shared/object/CreatureObject.cpp index 0fe535e5..2800d79b 100644 --- a/engine/server/library/serverGame/src/shared/object/CreatureObject.cpp +++ b/engine/server/library/serverGame/src/shared/object/CreatureObject.cpp @@ -11892,7 +11892,7 @@ void CreatureObject::setNumberOfMissionsWantedInMissionBag(int n) { // remove mission objects from the bag int j = 0; - for (iter = container->begin(), j = 0; iter != container->end(), j < i - n; ++iter, ++j) + for (iter = container->begin(), j = 0; (iter != container->end() && j < i - n); ++iter, ++j) { Object * const o = (*iter).getObject(); if (o) From 15fbd3445307e4350ef0d2f69cdedb518910670b Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Fri, 16 Oct 2015 23:34:57 -0500 Subject: [PATCH 4/5] almost no more warnings --- .../ServerCreatureObjectTemplate.cpp | 42 +++++++++---------- .../src/shared/MxCifQuadTreeBounds.h | 1 + .../src/shared/core/CSHandler.cpp | 2 +- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/engine/server/library/serverGame/src/shared/objectTemplate/ServerCreatureObjectTemplate.cpp b/engine/server/library/serverGame/src/shared/objectTemplate/ServerCreatureObjectTemplate.cpp index e5ba5655..babf8d0a 100644 --- a/engine/server/library/serverGame/src/shared/objectTemplate/ServerCreatureObjectTemplate.cpp +++ b/engine/server/library/serverGame/src/shared/objectTemplate/ServerCreatureObjectTemplate.cpp @@ -168,7 +168,7 @@ int ServerCreatureObjectTemplate::getAttributes(Attributes index) const base = dynamic_cast(m_baseData); } - DEBUG_FATAL(index < 0 || index >= 6, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 6, ("template param static_cast(index) (m_baseData); } - DEBUG_FATAL(index < 0 || index >= 6, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 6, ("template param static_cast(index) (m_baseData); } - DEBUG_FATAL(index < 0 || index >= 6, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 6, ("template param static_cast(index) (m_baseData); } - DEBUG_FATAL(index < 0 || index >= 6, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 6, ("template param static_cast(index) (m_baseData); } - DEBUG_FATAL(index < 0 || index >= 6, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 6, ("template param static_cast(index) (m_baseData); } - DEBUG_FATAL(index < 0 || index >= 6, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 6, ("template param static_cast(index) (m_baseData); } - DEBUG_FATAL(index < 0 || index >= 6, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 6, ("template param static_cast(index) (m_baseData); } - DEBUG_FATAL(index < 0 || index >= 6, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 6, ("template param static_cast(index) (m_baseData); } - DEBUG_FATAL(index < 0 || index >= 6, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 6, ("template param static_cast(index) getAttribModsCount(); - if (index < baseCount) + if (static_cast(index) < baseCount) { base->getAttribMods(data, index); return; @@ -1403,7 +1403,7 @@ void ServerCreatureObjectTemplate::getAttribMods(AttribMod &data, int index) con index -= baseCount; } - DEBUG_FATAL(index < 0 || static_cast(index) >= m_attribMods.size(), ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= m_attribMods.size(), ("template param static_cast(index) (structTemplate); @@ -1441,7 +1441,7 @@ void ServerCreatureObjectTemplate::getAttribModsMin(AttribMod &data, int index) if (m_attribModsAppend && base != NULL) { int baseCount = base->getAttribModsCount(); - if (index < baseCount) + if (static_cast(index) < baseCount) { base->getAttribModsMin(data, index); return; @@ -1449,7 +1449,7 @@ void ServerCreatureObjectTemplate::getAttribModsMin(AttribMod &data, int index) index -= baseCount; } - DEBUG_FATAL(index < 0 || static_cast(index) >= m_attribMods.size(), ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= m_attribMods.size(), ("template param static_cast(index) (structTemplate); @@ -1487,7 +1487,7 @@ void ServerCreatureObjectTemplate::getAttribModsMax(AttribMod &data, int index) if (m_attribModsAppend && base != NULL) { int baseCount = base->getAttribModsCount(); - if (index < baseCount) + if (static_cast(index) < baseCount) { base->getAttribModsMax(data, index); return; @@ -1495,7 +1495,7 @@ void ServerCreatureObjectTemplate::getAttribModsMax(AttribMod &data, int index) index -= baseCount; } - DEBUG_FATAL(index < 0 || static_cast(index) >= m_attribMods.size(), ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= m_attribMods.size(), ("template param static_cast(index) (structTemplate); @@ -2007,7 +2007,7 @@ float ServerCreatureObjectTemplate::getMaxMentalStates(MentalStates index) const base = dynamic_cast(m_baseData); } - DEBUG_FATAL(index < 0 || index >= 4, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 4, ("template param static_cast(index) (m_baseData); } - DEBUG_FATAL(index < 0 || index >= 4, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 4, ("template param static_cast(index) (m_baseData); } - DEBUG_FATAL(index < 0 || index >= 4, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 4, ("template param static_cast(index) (m_baseData); } - DEBUG_FATAL(index < 0 || index >= 4, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 4, ("template param static_cast(index) (m_baseData); } - DEBUG_FATAL(index < 0 || index >= 4, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 4, ("template param static_cast(index) (m_baseData); } - DEBUG_FATAL(index < 0 || index >= 4, ("template param index out of range")); + DEBUG_FATAL(static_cast(index) < 0 || static_cast(index) >= 4, ("template param static_cast(index) Date: Sat, 17 Oct 2015 00:43:39 -0500 Subject: [PATCH 5/5] strnlen is safer --- engine/client/application/Miff/src/lex_yy.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/engine/client/application/Miff/src/lex_yy.c b/engine/client/application/Miff/src/lex_yy.c index 449b767d..e9bd0436 100644 --- a/engine/client/application/Miff/src/lex_yy.c +++ b/engine/client/application/Miff/src/lex_yy.c @@ -4520,7 +4520,7 @@ static void yy_flex_strncpy (char *,yyconst char *,int ); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); +static int yy_flex_strnlen (yyconst char * ); #endif #ifndef YY_NO_INPUT @@ -4726,9 +4726,9 @@ YY_RULE_SETUP char *s; // allocate space for string and pass the string pointer rather then yytext count(); - s = MIFFallocString(strlen(yytext) + 1); + s = MIFFallocString(strnlen(yytext) + 1); strcpy(s, yytext+1); /* strip off the double quotes */ - s[strlen(yytext+1)-1] = 0; /* strip off the ending double quotes */ + s[strnlen(yytext+1)-1] = 0; /* strip off the ending double quotes */ yylval.stype = s; return(STR_LIT); } @@ -4977,7 +4977,7 @@ YY_RULE_SETUP char *s; // allocate space for string and pass the string pointer rather then yytext count(); - s = MIFFallocString(strlen(yytext) + 1); + s = MIFFallocString(strnlen(yytext) + 1); strcpy(s, yytext); yylval.stype = s; return(IDENTIFIER); @@ -5915,7 +5915,7 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) { - return yy_scan_bytes(yystr,strlen(yystr) ); + return yy_scan_bytes(yystr,strnlen(yystr) ); } /** Setup the input buffer state to scan the given bytes. The next call to yylex() will @@ -6126,7 +6126,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) +static int yy_flex_strnlen (yyconst char * s ) { register int n; for ( n = 0; s[n]; ++n ) @@ -6219,7 +6219,7 @@ void yyerror(char *err) /* called by yyparse() */ **-------------------------*/ int MIFFYYInput(char *buf,int max_size) { - int len = strlen(MIFFInputStream); + int len = strnlen(MIFFInputStream); int n = max_size < len ? max_size : len; if (n > 0) {