Skip to content

Commit 3efb6df

Browse files
committed
GH-68 Fix p4StrNum() should not parse "E" as a float.
1 parent 52d76c1 commit 3efb6df

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/post4.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ p4StrNum(P4_String str, int base, P4_Cell *out, int *is_float)
258258
/* We don't accept the double-cell notation 123. 0.
259259
* as this is confusing with floating point input.
260260
*/
261-
if (str.string[offset] == '.' || toupper(str.string[offset]) == 'E') {
261+
if (str.string[offset] == '.'
262+
|| (0 < offset && isdigit(str.string[offset-1]) && toupper(str.string[offset]) == 'E')) {
262263
if (base != 10) {
263264
return -1;
264265
}

test/float.p4

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ INCLUDE ../test/assert.p4
66

77
[ELSE]
88

9+
.( GH-68 e is not a float ) test_group
10+
t{ s" 0 0 efoobar-undefined-word" ' evaluate catch nip nip -> -13 }t
11+
test_group_end
12+
913
.( F0= ) test_group
1014
t{ 0.0 F0= -> TRUE }t
1115
t{ 1.0 F0= -> FALSE }t

0 commit comments

Comments
 (0)