fix(wasm): correct several bugs in realloc#5261
fix(wasm): correct several bugs in realloc#5261WillLillis merged 2 commits intotree-sitter:masterfrom
realloc#5261Conversation
|
what's the error when you try to build it? there is a cargo registry patch in master branch, you can replace it and remove the rust malloc workaround and try. https://github.com/trim21/beancount-format/tree/master/patches/tree-sitter-language-0.1.6 also I guess there are some bug when |
|
since you create a new PR I'll close my #5234 . |
|
also while we are fixing malloc, there is also a bug in calloc, if doesn't handle NULL from malloc: tree-sitter/crates/language/wasm/src/stdlib.c Lines 110 to 114 in 8816d44 |
This is with the following changes to the diff --git a/crates/beancount-formatter/Cargo.toml b/crates/beancount-formatter/Cargo.toml
index 17113f6..8e2f654 100644
--- a/crates/beancount-formatter/Cargo.toml
+++ b/crates/beancount-formatter/Cargo.toml
@@ -16,7 +16,8 @@ wasm = ["tree-sitter-beancount/wasm"]
[dependencies]
tree-sitter-beancount = { git = "https://github.com/trim21/tree-sitter-beancount", branch = "wasm", default-features = false }
# tree-sitter-beancount = { path = "C:/Users/trim21/projects/tree-sitter-beancount/", default-features = false }
-tree-sitter = { version = "0.26.3" }
+# tree-sitter = { version = "0.26.3" }
+tree-sitter = { path = "../../../tree-sitter/lib" }
anyhow.workspace = true
serde.workspace = true
ropey = '1.6.1' |
there is a version spec that |
How were you testing your changes then? Edit: I see, nevermind. |
|
there is a It's a small enough change so I think you can only change content of https://github.com/trim21/beancount-format/blob/master/patches/tree-sitter-language-0.1.6/wasm/src/stdlib.c and also remove these workaround |
- free memory if 0 size is passed in - Don't `memcpy` contents if new pointer is `NULL` - Copy old region's contents only up to size of new region - free old region Co-authored-by: trim21 <i@trim21.me>
Co-authored-by: trim21 <i@trim21.me>
ee26b3a to
b714e2a
Compare
|
Replaced the contents of |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin release-0.26
git worktree add -d .worktree/backport-5261-to-release-0.26 origin/release-0.26
cd .worktree/backport-5261-to-release-0.26
git switch --create backport-5261-to-release-0.26
git cherry-pick -x f9d64425dbea3e286e9092e6f5ccd599e728cbc0 b714e2a7c01e8d5abab526f23e40b77c33babcb4 |
|
there is indeed some bug in these code tree-sitter/crates/language/wasm/src/stdlib.c Lines 128 to 135 in 4f8983b
haven't findout why... |

free memory if 0 size is passed in
Don't
memcpycontents if new pointer isNULLCopy old region's contents only up to size of new region
free old region
also exit early from
callocif call tomallocfailsSupersedes #5234 with more minimal changes and test coverage for the bug.
CC @trim21 I wasn't able to get
beancount-formatto build locally to give this change a try on your original repro from #5205. If you get a chance to try it out let me know!