Am 27.02.2015 um 18:47 schrieb rik:
2/27/15
Dan Sebald found a subtle bug in the use of the C++ string find functions
that was leading to segfaults.
-- Code --
size_t pos = file.find_first_not_of ("|");
if (pos > 0)
file = file.substr (pos);
else
-- End Code --
I think the idea here was to check if the first char in file is "|" and
omit the check (because we are building a pipe) for an existent
directory in the else path.
The issue is that the size_t is an unsigned quantity and the find functions
do not return -1 on failure as do regular C functions. Instead they return
std::string::npos (a very large number) when they fail to find the search term.
This was easily corrected to
-- Code --
size_t pos = file.find_first_not_of ("|");
if (pos != std::string::npos)
file = file.substr (pos);
else
-- End Code --
Please correct me if I'm wrong but shouldn't this then be
-- Code --
size_t pos = file.find_first_not_of ("|");
if (pos != std::string::npos && pos > 0)
-- End Code --