Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm: slice copy bombing out #64

Closed
trashhalo opened this issue Oct 29, 2018 · 3 comments
Closed

wasm: slice copy bombing out #64

trashhalo opened this issue Oct 29, 2018 · 3 comments

Comments

@trashhalo
Copy link

trashhalo commented Oct 29, 2018

A little toy program I was working on keeps hitting an error in the webassembly code for slicecopy. I don't see anything obviously wrong, so it might be a bug. happens if I try and call updatePage from javascript.

package main

import (
	"strconv"
	"strings"
)

func main() {
}

//go:export updatePage
func updatePage(x, y int) string {
	page := strings.Join([]string{
		"<div style=\"",
		"position:absolute; ",
		"width:50px; ",
		"height:50px; ",
		"background: red; ",
		"left: ",
		strconv.Itoa(x),
		"px; top: ",
		strconv.Itoa(y),
		"px;\"></div>",
	}, "")
	return page
}
@aykevl
Copy link
Member

aykevl commented Oct 29, 2018

Yes, that looks like a bug. Thank you for the report! Currently investigating.

However, note that you can't currently return a string from WebAssembly. This is a limitation of WebAssembly at the moment. In my experiments, it doesn't return anything at the moment, probably because it stores a pointer to the result somewhere but I don't know where exactly. Also, it appears to skip the first parameter for some reason.

@aykevl aykevl closed this as completed in 772c648 Oct 29, 2018
@aykevl
Copy link
Member

aykevl commented Oct 29, 2018

It was an incorrect backwards copy of a zero-length slice: even while being zero length, it tried to copy one byte. The bug should be fixed now.

I still don't understand why the first parameter from JS is skipped. It looks like it happens during WebAssembly codegen (after all optimization passes etc. have run) because the function signature in the IR is correct: two i32 parameters.

You can test that the function works by printing the resulting string to the console:

    println(page)

@trashhalo
Copy link
Author

wow fast turn around! oh yea my actual code isnt returning a string I just tried to hack it up to make sense in isolation.

thanks so much for your work on this project!

ZauberNerd pushed a commit to ZauberNerd/tinygo that referenced this issue Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants