Discussion:
[asio-users] Protect against calling buffer(vector<non_pod>)
Igor R
2013-03-12 09:53:27 UTC
Permalink
Hello,

In the current implementation the following code would compile, but produce UB:

string s = "a string";
vector<const_buffer> v;
v.push_back(buffer(s));
write(socket_, buffer(vec)); // NOTE incorrect buffer(); should be
just write(socket_, vec);


Isn't it worth trying to protect such a missuse by
enable_if<is_pod<.....> >? Like this:
template <typename PodType, typename Allocator>
inline mutable_buffers_1 buffer(std::vector<PodType, Allocator>& data,
typename boost::enable_if<boost::is_pod<PodType> >::type *t = 0)
{
....
}




Thanks.
Igor R
2013-03-12 10:29:45 UTC
Permalink
Post by Igor R
Isn't it worth trying to protect such a missuse by
template <typename PodType, typename Allocator>
inline mutable_buffers_1 buffer(std::vector<PodType, Allocator>& data,
typename boost::enable_if<boost::is_pod<PodType> >::type *t = 0)
{
....
}
I've submitted the ticket:
https://svn.boost.org/trac/boost/ticket/8284

Loading...