Fixed: Minor bug in ecompile allowing Double in the form "2d4".

These were incorrectly interpreted as "2e4", meaning 20000 and
leading to confusion with dice rolls. The compiler now issues an
error instead.
Added related test cases.
This commit is contained in:
Gabriele Tozzi 2016-01-22 00:16:39 +01:00
parent 8ed67905d0
commit 861ff58d1d
7 changed files with 149 additions and 1 deletions

View file

@ -2,9 +2,17 @@
<ESCRIPT>
<header>
<topic>Latest Core Changes</topic>
<datemodified>01-20-2016</datemodified>
<datemodified>01-22-2016</datemodified>
</header>
<version name="POL099">
<entry>
<date>01-22-2016</date>
<author>Bodom:</author>
<change type="Fixed">Minor bug in ecompile allowing Double literals in the form &quot;2d4&quot;.<br/>
These were incorrectly interpreted as &quot;2e4&quot;, meaning 20000 and<br/>
leading to confusion with dice rolls. The compiler now issues<br/>
an error instead.</change>
</entry>
<entry>
<date>01-20-2016</date>
<author>Bodom:</author>

View file

@ -1137,6 +1137,28 @@ namespace Pol {
char *endptr, *endptr2;
int l = strtol( ctx.s, &endptr, 0 );
double d = strtod( ctx.s, &endptr2 );
// 2015-01-21 Bodom: weird trick to remove an unwanted feature from Microsoft compiler
// interpreting 'd' as 'e' (exponent), but 'd' in UO means dice,
// leading to confusion
// TODO: The best solution would be to reimplement the int/double parsing
if( ! ( ctx.s[0] == '0' && ctx.s[1] && ( ctx.s[1] == 'x' || ctx.s[1] == 'X' ) ) ) {
// This is not hex, so no 'd' can be valid
for( const char* i = ctx.s; i <= endptr2; i++ ) {
if( *i == 'd' || *i == 'D' ) {
// A 'd' has been eaten, bug could have occurred:
// re-perform parsing on a cleaned version of the string
size_t safelen = i - ctx.s + 1;
std::unique_ptr<char[]> safeptr( new char[safelen] );
strncpy( safeptr.get(), ctx.s, safelen );
d = strtod( safeptr.get(), &endptr2 );
size_t newlen = endptr2 - safeptr.get();
endptr2 = const_cast<char*>(ctx.s + newlen);
break;
}
}
}
tok.type = TYP_OPERAND;
if ( endptr >= endptr2 )
{ // long got more out of it, we'll go with that

View file

@ -1,4 +1,9 @@
-- POL099 --
01-22-2016 Bodom:
Fixed: Minor bug in ecompile allowing Double literals in the form "2d4".
These were incorrectly interpreted as "2e4", meaning 20000 and
leading to confusion with dice rolls. The compiler now issues
an error instead.
01-20-2016 Bodom:
Added: New Item.house property, returns a reference to the house if the
item is a component of it (listed in House.components()).

View file

View file

@ -0,0 +1 @@
0

View file

@ -0,0 +1,48 @@
1.
Integer
0
2.
Integer
-2147483647
3.
Integer
2147483647
4.
Integer
267391546
5.
Integer
178956960
6.
Integer
-255
7.
Integer
0
8.
Integer
55
9.
Integer
493
10.
Double
0
11.
Double
-2.14748e+009
12.
Double
2.14748e+009
13.
Double
77.77
14.
Double
1
15.
Double
2e+009
16.
Double
2e+009

View file

@ -0,0 +1,64 @@
// Testing all numeric creation possibilities
var t;
var n := 0;
function testPrint(num)
n += 1;
print(CStr(n) + ".");
print(TypeOf(t));
print(t);
endfunction
// Int
t := 0;
testPrint(t);
t := -2147483648;
testPrint(t);
t := 2147483647;
testPrint(t);
t := 0xfF0123a;
testPrint(t);
t := 0Xaaaaaa0;
testPrint(t);
t := -0Xff;
testPrint(t);
t := 000000;
testPrint(t);
t := 0000067;
testPrint(t);
t := 0755;
testPrint(t);
// Dbl
t := 0.0;
testPrint(t);
t := -2147483648.123456;
testPrint(t);
t := 2147483647.123456;
testPrint(t);
t := 077.77;
testPrint(t);
t := 1.000000000000000000000000000000001;
testPrint(t);
t := 2e9;
testPrint(t);
t := 2E9;
testPrint(t);