From bf30c76c94390e81b29ac59b3d98487b5ab7985e Mon Sep 17 00:00:00 2001 From: pwnker Date: Thu, 25 Apr 2024 01:16:00 +0200 Subject: [PATCH] [std.porth] fix: memset bug :O --- .gitignore | 1 + std/std.porth | 2 +- tests/memset-bug.porth | 14 ++++++++++++++ tests/memset-bug.txt | 10 ++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/memset-bug.porth create mode 100644 tests/memset-bug.txt diff --git a/.gitignore b/.gitignore index e29f1b0..22d5e36 100644 --- a/.gitignore +++ b/.gitignore @@ -76,3 +76,4 @@ tests/memset tests/envp tests/local-memory-overshadowing tests/backslash-in-strlit +tests/memset-bug diff --git a/std/std.porth b/std/std.porth index ee46c0d..d3b6f9d 100644 --- a/std/std.porth +++ b/std/std.porth @@ -700,7 +700,7 @@ in byte !64 data @ptr swap while dup 0 > do - byte @64 data @ptr !64 + byte @64 data @ptr !8 data inc64 1 - end diff --git a/tests/memset-bug.porth b/tests/memset-bug.porth new file mode 100644 index 0000000..4bb1860 --- /dev/null +++ b/tests/memset-bug.porth @@ -0,0 +1,14 @@ + +include "std/std.porth" + +const N 32 end +memory xs N end + +0 while dup N < do + 'a' over xs + !8 + 1 + +end drop + +N xs puts "\n" puts +15 'b' xs memset drop +N xs puts "\n" puts diff --git a/tests/memset-bug.txt b/tests/memset-bug.txt new file mode 100644 index 0000000..f5cd321 --- /dev/null +++ b/tests/memset-bug.txt @@ -0,0 +1,10 @@ +:i argc 0 +:b stdin 0 + +:i returncode 0 +:b stdout 66 +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +bbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaa + +:b stderr 0 +