Change SGPath::pathListSep into a const char array of size 2
Previously, SGPath::pathListSep was a char in static memory, that could be followed by anything (often '\0', as it seems... but not always). This is (was) dangerous, because it is then tempting to take its address and pass it to functions expecting a char * corresponding to a null-terminated string (C-style). SGPath::pathListSep is now a static array of two const chars: the path list separator followed by a '\0'. This implies that &SGPath::pathListSep can now be reliably interpreted as a C-style string of length 1 (not counting the null terminator), containing only the path list separator.
This commit is contained in:
parent
36275f5cce
commit
a962c90b30
@ -53,9 +53,9 @@ static const char sgDirPathSep = '/';
|
||||
static const char sgDirPathSepBad = '\\';
|
||||
|
||||
#ifdef _WIN32
|
||||
const char SGPath::pathListSep = ';';
|
||||
const char SGPath::pathListSep[] = ";"; // this is null-terminated
|
||||
#else
|
||||
const char SGPath::pathListSep = ':';
|
||||
const char SGPath::pathListSep[] = ":"; // ditto
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -332,7 +332,7 @@ SGPath SGPath::operator/( const std::string& p ) const
|
||||
#if defined(ENABLE_OLD_PATH_API)
|
||||
//add a new path component to the existing path string
|
||||
void SGPath::add( const string& p ) {
|
||||
append( SGPath::pathListSep+p );
|
||||
append( SGPath::pathListSep[0] + p );
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -664,7 +664,7 @@ string_list sgPathSplit( const string &search_path ) {
|
||||
bool done = false;
|
||||
|
||||
while ( !done ) {
|
||||
int index = tmp.find(SGPath::pathListSep);
|
||||
int index = tmp.find(SGPath::pathListSep[0]);
|
||||
if (index >= 0) {
|
||||
result.push_back( tmp.substr(0, index) );
|
||||
tmp = tmp.substr( index + 1 );
|
||||
|
@ -52,8 +52,8 @@ class SGPath {
|
||||
|
||||
public:
|
||||
|
||||
// OS-dependent separator used in paths lists
|
||||
static const char pathListSep;
|
||||
// OS-dependent separator used in paths lists (C-style string of length 1)
|
||||
static const char pathListSep[2];
|
||||
|
||||
struct Permissions
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user