mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-02-17 01:22:18 +00:00
Fixed an issue where the ZScript parser aborted with a cryptic error message when encountering a number that was too small or big. It now clamps the value to min/max for the data type and prints a warning
This commit is contained in:
parent
8824a2bb94
commit
2699f5793b
2 changed files with 32 additions and 1 deletions
|
@ -309,6 +309,10 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
return null;
|
||||
}
|
||||
|
||||
// biwa. Report a recoverable parsing problem
|
||||
if (!string.IsNullOrEmpty(token.WarningMessage))
|
||||
LogWarning(token.WarningMessage);
|
||||
|
||||
if ((token.Type == ZScriptTokenType.Semicolon ||
|
||||
token.Type == ZScriptTokenType.Comma) && nestingLevel == 0 && !betweenparen)
|
||||
{
|
||||
|
|
|
@ -101,6 +101,7 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
public ZScriptToken()
|
||||
{
|
||||
IsValid = true;
|
||||
WarningMessage = String.Empty;
|
||||
}
|
||||
|
||||
public ZScriptTokenType Type { get; internal set; }
|
||||
|
@ -108,6 +109,7 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
public int ValueInt { get; internal set; }
|
||||
public double ValueDouble { get; internal set; }
|
||||
public bool IsValid { get; internal set; }
|
||||
public string WarningMessage { get; internal set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
@ -330,9 +332,34 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
tok.ValueInt = (int)tok.ValueDouble;
|
||||
}
|
||||
}
|
||||
catch (OverflowException) // biwa. If the value is too small or too big set it to the min or max, and set a warning message
|
||||
{
|
||||
tok.WarningMessage = "Number " + tok.Value + " too " + (tok.Value[0] == '-' ? "small" : "big") + ". Set to ";
|
||||
|
||||
if (ishex || isoctal || !isdouble)
|
||||
{
|
||||
if (tok.Value[0] == '-')
|
||||
tok.ValueInt = Int32.MinValue;
|
||||
else
|
||||
tok.ValueInt = Int32.MaxValue;
|
||||
|
||||
tok.ValueDouble = tok.ValueInt;
|
||||
tok.WarningMessage += tok.ValueInt;
|
||||
}
|
||||
else if (isdouble)
|
||||
{
|
||||
if (tok.Value[0] == '-')
|
||||
tok.ValueDouble = Double.MinValue;
|
||||
else
|
||||
tok.ValueDouble = Double.MaxValue;
|
||||
|
||||
tok.ValueInt = (int)tok.ValueDouble;
|
||||
tok.WarningMessage += tok.ValueDouble;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//throw new Exception(tok.ToString());
|
||||
// throw new Exception(tok.ToString());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue