diff --git a/impls/wasm/platform_wasi.wam b/impls/wasm/platform_wasi.wam index e5d064c9..c52c0f2b 100644 --- a/impls/wasm/platform_wasi.wam +++ b/impls/wasm/platform_wasi.wam @@ -49,7 +49,12 @@ (if (i32.le_s (i32.load $nread_ptr) 0) (return 0)) ;; Replace ending newline with NULL - (i32.store8 (i32.add $buf (i32.sub (i32.load $nread_ptr) 1)) 0) + ;; NOTE: oddly, there isn't always a newline so check first + ;; Specifically, this input chops too much: + ;; (abcd abcdefg (abc (n) (if (> n 0) (+ n (abcdefg (- n 1))) 0))) + (if (i32.eq (CHR "\n") + (i32.load8_u (i32.add $buf (i32.sub (i32.load $nread_ptr) 1)) 0)) + (i32.store8 (i32.add $buf (i32.sub (i32.load $nread_ptr) 1)) 0)) 1 )