diff --git a/scripts/integration_test.sh b/scripts/integration_test.sh index 90169ad4c..b9ef6a79f 100755 --- a/scripts/integration_test.sh +++ b/scripts/integration_test.sh @@ -120,8 +120,14 @@ port=17822 cp ../ubsan.supp . +if [[ $OSTYPE == 'darwin'* ]]; then + DETECT_LEAKS=0 +else + DETECT_LEAKS=1 +fi + export UBSAN_OPTIONS=suppressions=./ubsan.supp:log_path=./SAN:print_stacktrace=1:halt_on_errors=0 -export ASAN_OPTIONS=log_path=./SAN:print_stacktrace=1:check_initialization_order=1:detect_leaks=1:halt_on_errors=0 +export ASAN_OPTIONS=log_path=./SAN:print_stacktrace=1:check_initialization_order=1:detect_leaks=$DETECT_LEAKS:halt_on_errors=0 function print_san() { if test -n "$(find . -maxdepth 1 -name 'SAN.*' -print -quit)" @@ -181,14 +187,15 @@ wait sleep 1 ranks="$(sqlite3 ddnet-server.sqlite < <(echo "select * from record_race;"))" +num_ranks="$(echo "$ranks" | wc -l | xargs)" if [ "$ranks" == "" ] then touch fail_ranks.txt echo "[-] Error: no ranks found in database" -elif [ "$(echo "$ranks" | wc -l)" != "1" ] +elif [ "$num_ranks" != "1" ] then touch fail_ranks.txt - echo "[-] Error: expected 1 rank got $(echo "$ranks" | wc -l)" + echo "[-] Error: expected 1 rank got $num_ranks" elif ! echo "$ranks" | grep -q client1 then touch fail_ranks.txt @@ -213,4 +220,3 @@ else fi print_san || exit 1 - diff --git a/src/base/vmath.h b/src/base/vmath.h index 5923fbb9d..7fb074b9a 100644 --- a/src/base/vmath.h +++ b/src/base/vmath.h @@ -124,14 +124,17 @@ inline float angle(const vector2_base &a) template inline vector2_base normalize_pre_length(const vector2_base &v, T len) { + if(len == 0) + return vector2_base(); return vector2_base(v.x / len, v.y / len); - float l = (float)(1.0f / sqrtf(v.x * v.x + v.y * v.y)); - return vector2_base(v.x * l, v.y * l); } inline vector2_base normalize(const vector2_base &v) { - float l = (float)(1.0f / sqrtf(v.x * v.x + v.y * v.y)); + float divisor = sqrtf(v.x * v.x + v.y * v.y); + if(divisor == 0.0f) + return vector2_base(0.0f, 0.0f); + float l = (float)(1.0f / divisor); return vector2_base(v.x * l, v.y * l); } @@ -273,7 +276,10 @@ inline float length(const vector3_base &a) inline vector3_base normalize(const vector3_base &v) { - float l = (float)(1.0f / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z)); + float divisor = sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); + if(divisor == 0.0f) + return vector3_base(0.0f, 0.0f, 0.0f); + float l = (float)(1.0f / divisor); return vector3_base(v.x * l, v.y * l, v.z * l); } diff --git a/src/game/client/prediction/gameworld.cpp b/src/game/client/prediction/gameworld.cpp index 8d516b5b7..56bf2344f 100644 --- a/src/game/client/prediction/gameworld.cpp +++ b/src/game/client/prediction/gameworld.cpp @@ -144,12 +144,14 @@ void CGameWorld::RemoveEntity(CEntity *pEnt) if(pEnt->m_ObjType == ENTTYPE_CHARACTER) { - CCharacter *pChar = (CCharacter *)pEnt; - int ID = pChar->GetCID(); - if(ID >= 0 && ID < MAX_CLIENTS) + if(CCharacter *pChar = dynamic_cast(pEnt)) { - m_apCharacters[ID] = 0; - m_Core.m_apCharacters[ID] = 0; + int ID = pChar->GetCID(); + if(ID >= 0 && ID < MAX_CLIENTS) + { + m_apCharacters[ID] = 0; + m_Core.m_apCharacters[ID] = 0; + } } }