Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::asio::buffer bug with string literal
From: Richard Hodges (hodges.r_at_[hidden])
Date: 2017-11-29 06:47:11


On 29 November 2017 at 02:58, Gavin Lambert via Boost-users <
boost-users_at_[hidden]> wrote:

> On 29/11/2017 01:57, Richard Hodges wrote:
>
>> It gives me the shivers. Binary data could easily have a zero in the last
>> byte.
>>
>
> In theory those should be distinguishable -- char is a distinct type from
> unsigned char (even if char is unsigned by default), and *hopefully* anyone
> poking binary data at the wire is doing so as an unsigned char or uint8_t.
>

In reality, in my world (e.g. protocol buffers), std::string is a more
useful type for binary data buffers that std::vector<std::uint8_t>. I know
it's a different type, but still, it's chars modelling bytes. This is not
an uncommon idea.

The fact that you can't construct a std::vector from data without a copy
means that std::vector<byte> is less suitable for buffering data than one
might imagine.

>
> In practice, there might be some trouble with people abusing std::string
> as if it were std::vector<uint8_t> by pointer casting.
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net