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

BitStream::Read/Write make a poor assumption about trivial-copyability #61

Open
BrodyHiggerson opened this issue Mar 17, 2020 · 0 comments

Comments

@BrodyHiggerson
Copy link

After not working with SLikeNet (or RakNet in my case) for a while, I came back to it and made a simple mistake that the library and API happily let me do.

I passed a std::string to BitStream::Write, and then received it via BitStream::Read(std::string&). Because I was testing client+server in the same process, it didn't crash immediately. What happened was the BitStream happily serialized the entire string, not just its contents, and then reassembled on the other side, such that the server and client strings were both pointing to the same string memory, and so when the client's string was destroyed going out of scope, it took the server's string out with it.

I don't think it's sensible for the catch-all templated functions to allow this. Instead, they should static_assert on std::is_trivially_copyable, such that a template specialization is required if the user is trying to serialize a not as-of-yet supported type.

This would help solidify the API and avoid a very simple beginner-trap of an issue.

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

1 participant