fixed bad parameter types in direct native functions.

bool can cause undefined behavior here, these should be int.
This commit is contained in:
Christoph Oelckers 2023-11-07 18:06:50 +01:00
parent fb6e4becaa
commit d5e9783324
3 changed files with 4 additions and 6 deletions

View file

@ -1,5 +1,4 @@
/*
/*
** serializer.cpp
** Savegame wrapper around RapidJSON
**

View file

@ -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);

View file

@ -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);
}