Skip to content

Commit

Permalink
GH-68 Fix p4StrNum() should not parse "E" as a float.
Browse files Browse the repository at this point in the history
  • Loading branch information
SirWumpus committed Nov 11, 2024
1 parent 52d76c1 commit 3efb6df
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/post4.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ p4StrNum(P4_String str, int base, P4_Cell *out, int *is_float)
/* We don't accept the double-cell notation 123. 0.
* as this is confusing with floating point input.
*/
if (str.string[offset] == '.' || toupper(str.string[offset]) == 'E') {
if (str.string[offset] == '.'
|| (0 < offset && isdigit(str.string[offset-1]) && toupper(str.string[offset]) == 'E')) {
if (base != 10) {
return -1;
}
Expand Down
4 changes: 4 additions & 0 deletions test/float.p4
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ INCLUDE ../test/assert.p4

[ELSE]

.( GH-68 e is not a float ) test_group
t{ s" 0 0 efoobar-undefined-word" ' evaluate catch nip nip -> -13 }t
test_group_end

.( F0= ) test_group
t{ 0.0 F0= -> TRUE }t
t{ 1.0 F0= -> FALSE }t
Expand Down

0 comments on commit 3efb6df

Please sign in to comment.