Skip to content

Commit 48c22c6

Browse files
committed
Stricter float_of_string
1 parent aede507 commit 48c22c6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

runtime/wasm/float.wat

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,12 @@
483483
(array.new_data $string $float_of_string (i32.const 0) (i32.const 15)))
484484
(f64.const 0))
485485

486+
(func $on_whitespace (param $s (ref $string)) (param $i i32) (result i32)
487+
(local $c i32)
488+
(local.set $c (array.get_u $string (local.get $s) (local.get $i)))
489+
(i32.or (i32.eq (local.get $c) (i32.const 32)) ;; ' '
490+
(i32.le_u (i32.sub (local.get $c) (i32.const 9)) (i32.const 4))))
491+
486492
(func (export "caml_float_of_string") (param (ref eq)) (result (ref eq))
487493
(local $s (ref $string)) (local $len i32) (local $i i32) (local $j i32)
488494
(local $s' (ref $string))
@@ -525,13 +531,15 @@
525531
(loop $skip_spaces
526532
(if (i32.lt_u (local.get $i) (local.get $len))
527533
(then
528-
(if (i32.eq (i32.const 32) ;; ' '
529-
(array.get_u $string (local.get $s) (local.get $i)))
534+
(if (call $on_whitespace (local.get $s) (local.get $i))
530535
(then
531536
(local.set $i (i32.add (local.get $i) (i32.const 1)))
532537
(br $skip_spaces))))))
533538
(block $error
534539
(br_if $error (i32.eq (local.get $i) (local.get $len)))
540+
(br_if $error
541+
(call $on_whitespace
542+
(local.get $s) (i32.sub (local.get $len) (i32.const 1))))
535543
(local.set $c (array.get_u $string (local.get $s) (i32.const 0)))
536544
(if (i32.eq (local.get $c) (i32.const 45)) ;; '-'
537545
(then

0 commit comments

Comments
 (0)