Subject: [Boost-bugs] [Boost C++ Libraries] #2403: Conversion of fixed size char array by lexical_cast
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-10-10 09:26:43
#2403: Conversion of fixed size char array by lexical_cast
-------------------------------------------+--------------------------------
Reporter: Chard | Owner: nasonov
Type: Bugs | Status: new
Milestone: | Component: lexical_cast
Version: Boost 1.34.1 | Severity: Problem
Keywords: lexical_cast fixed char array |
-------------------------------------------+--------------------------------
I can't say if this counts as a bug, since it is very contrived, but it
does have a possibly unintended side-effect.
If ''lexical_cast'' is used to convert a fixed size char array, it will
happily compile but, it will be treated as a null-terminated char array.
This means it will run off the end of the fixed length array.
E.g.
{{{
struct Data
{
Data()
{
fixedLengthField[0] = '0';
fixedLengthField[1] = '1';
fixedLengthField[2] = '2';
fixedLengthField[3] = '3';
moreData[0] = 'X';
moreData[1] = '\0';
}
// pack(1)
char fixedLengthField[4];
char moreData[2];
};
void
test()
{
Data d;
std::string x = boost::lexical_cast<std::string>(d.fixedLengthField);
assert(x.size() == sizeof(d.fixedLengthField));
}
}}}
-- Ticket URL: <http://svn.boost.org/trac/boost/ticket/2403> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:58 UTC