Skip to content

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

@BrodyHiggerson

Description

@BrodyHiggerson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions