Subject: [Boost-bugs] [Boost C++ Libraries] #6874: Path should have a size() member function
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-05-07 11:12:18
#6874: Path should have a size() member function
----------------------------------------------+-----------------------------
Reporter: Gary Sanders <lex21@â¦> | Owner: bemandawes
Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: filesystem
Version: Boost 1.49.0 | Severity: Problem
Keywords: path size |
----------------------------------------------+-----------------------------
It would be convenient for filesystem::path to provide a size() member
function, especially for circumstances that require interface with legacy
windows apps and functions.
Consider the traditional windows path buffer:
{{{
wchar_t legacy [_MAX_PATH];
}}}
and a boost path:
{{{
boost::filesystem::path path = L"<...>";
}}}
In order to ensure that buffer overruns do not occur when copying into a
legacy buffer, assuming that querying the size of the wstring() member
function is the same as the c_str() size, code similar to the following is
required:
{{{
if (path.wstring().size()+1 <= _MAX_PATH)
{
wcscpy(&legacy[0], path.c_str());
}
else
{
// buffer would overrun, do something else ...
}
}}}
It would be more convenient, and arguably safer, if filesystem::path
provides the size of the string that is referenced by the c_str()
function.
{{{
if (path.size()+1 <= _MAX_PATH)
{
wcscpy(&legacy[0], path.c_str());
}
else
{
// buffer would overrun, do something else ...
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/6874> 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:50:09 UTC