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

Incorrect WriteAt implementation for mem.File #286

Closed
tdakkota opened this issue Feb 12, 2021 · 1 comment · Fixed by #287
Closed

Incorrect WriteAt implementation for mem.File #286

tdakkota opened this issue Feb 12, 2021 · 1 comment · Fixed by #287

Comments

@tdakkota
Copy link
Contributor

tdakkota commented Feb 12, 2021

To reproduce: https://play.golang.org/p/-mM7CBvnFVl

I'd put fmt.Println(f.fileData.data) to (*mem.File).WriteAt, so I got

[0 0 0 0 0 1 2 3 4 5]
[1 2 3 4 5 1 2 3 4 5]
[1 2 3 4 5 1 2 3 4 5 1 2 3 4 5]
[0 0 0 0 0 1 2 3 4 5]
[0 0 0 0 0 1 2 3 4 5]

Seems like Write does not copy old data if reallocation needed.

@tdakkota
Copy link
Contributor Author

Also, there is a possible race condition
Between

atomic.StoreInt64(&f.at, off)

and
cur := atomic.LoadInt64(&f.at)

f.at can be mutated

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

Successfully merging a pull request may close this issue.

1 participant