From d5e9783324936b50eb4b7b8ed646894a30e226b2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 7 Nov 2023 18:06:50 +0100 Subject: [PATCH] fixed bad parameter types in direct native functions. bool can cause undefined behavior here, these should be int. --- src/common/engine/serializer.cpp | 1 - src/common/scripting/interface/vmnatives.cpp | 6 +++--- src/common/utility/geometry.h | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/common/engine/serializer.cpp b/src/common/engine/serializer.cpp index 7fbf7adc6b8..34fd6956b59 100644 --- a/src/common/engine/serializer.cpp +++ b/src/common/engine/serializer.cpp @@ -1,5 +1,4 @@ /* -/* ** serializer.cpp ** Savegame wrapper around RapidJSON ** diff --git a/src/common/scripting/interface/vmnatives.cpp b/src/common/scripting/interface/vmnatives.cpp index 1df737d165b..5ab3051d443 100644 --- a/src/common/scripting/interface/vmnatives.cpp +++ b/src/common/scripting/interface/vmnatives.cpp @@ -668,7 +668,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetBottomAlignOffset, GetBottomAlignOffset) ACTION_RETURN_FLOAT(GetBottomAlignOffset(self, code)); } -static int StringWidth(FFont *font, const FString &str, bool localize) +static int StringWidth(FFont *font, const FString &str, int localize) { const char *txt = (localize && str[0] == '$') ? GStrings(&str[1]) : str.GetChars(); return font->StringWidth(txt); @@ -682,7 +682,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(FFont, StringWidth, StringWidth) ACTION_RETURN_INT(StringWidth(self, str, localize)); } -static int GetMaxAscender(FFont* font, const FString& str, bool localize) +static int GetMaxAscender(FFont* font, const FString& str, int localize) { const char* txt = (localize && str[0] == '$') ? GStrings(&str[1]) : str.GetChars(); return font->GetMaxAscender(txt); @@ -696,7 +696,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetMaxAscender, GetMaxAscender) ACTION_RETURN_INT(GetMaxAscender(self, str, localize)); } -static int CanPrint(FFont *font, const FString &str, bool localize) +static int CanPrint(FFont *font, const FString &str, int localize) { const char *txt = (localize && str[0] == '$') ? GStrings(&str[1]) : str.GetChars(); return font->CanPrint(txt); diff --git a/src/common/utility/geometry.h b/src/common/utility/geometry.h index e6b19db3852..3a7bb8d9c8a 100644 --- a/src/common/utility/geometry.h +++ b/src/common/utility/geometry.h @@ -150,7 +150,7 @@ inline double InterceptLineSegments(double v2x, double v2y, double v2dx, double den = 1 / den; double factor1 = ((v2x - v1x) * v2dy + (v1y - v2y) * v2dx) * -den; - if (factor1 < 0 || factor1 > 1) return -FLT_MAX; // no intersection + if (factor1 < 0 || factor1 >= 1) return -FLT_MAX; // no intersection if (pfactor1) *pfactor1 = factor1; return ((v1x - v2x) * v1dy + (v2y - v1y) * v1dx) * den; // this one's for the line segment where we want to get the intercept factor for so it needs to be last. @@ -232,4 +232,3 @@ inline bool BoxInRange(const DVector2& boxtl, const DVector2& boxbr, const DVect boxtl.Y < max(start.Y, end.Y) && boxbr.Y > min(start.Y, end.Y); } -