Fixed read of potentially junk values in ZScript parser

The following ill-formed ZScript code might crash targets with sizeof(int) != sizeof(void*) like 64-bit Intel
class test { void func() { if (true) ( return; ) } }
This commit is contained in:
alexey.lysiuk 2018-02-21 15:17:02 +02:00
parent 420602e154
commit 74357ced0c
2 changed files with 21 additions and 0 deletions

View file

@ -267,6 +267,7 @@ static void ParseSingleFile(FScanner *pSC, const char *filename, int lump, void
while (sc.GetToken()) while (sc.GetToken())
{ {
value.Largest = 0;
value.SourceLoc = sc.GetMessageLine(); value.SourceLoc = sc.GetMessageLine();
switch (sc.TokenType) switch (sc.TokenType)
{ {

View file

@ -7,11 +7,31 @@
struct ZCCToken struct ZCCToken
{ {
template <typename... Ts>
struct TLargest;
template <typename T>
struct TLargest<T>
{
using Type = T;
};
template <typename T, typename U, typename... Ts>
struct TLargest<T, U, Ts...>
{
using Type = typename TLargest<
typename std::conditional<
(sizeof(T) > sizeof(U)), T, U
>::type, Ts...
>::Type;
};
union union
{ {
int Int; int Int;
double Float; double Float;
FString *String; FString *String;
TLargest<decltype(Int), decltype(Float), decltype(String)>::Type Largest;
}; };
int SourceLoc; int SourceLoc;