Fix using invalid string index in wxIsAbsolutePath()
Check if the path is at least two characters long before accessing its second character. Add test cases for wxIsAbsolutePath() on MS Windows. Closes https://github.com/wxWidgets/wxWidgets/pull/2262
This commit is contained in:
@@ -254,12 +254,13 @@ wxIsAbsolutePath (const wxString& filename)
|
|||||||
if (filename[0] == wxT('/'))
|
if (filename[0] == wxT('/'))
|
||||||
return true;
|
return true;
|
||||||
#ifdef __VMS__
|
#ifdef __VMS__
|
||||||
if ((filename[0] == wxT('[') && filename[1] != wxT('.')))
|
if (filename.size() > 1 && (filename[0] == wxT('[') && filename[1] != wxT('.')))
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
#if defined(__WINDOWS__)
|
#if defined(__WINDOWS__)
|
||||||
// MSDOS like
|
// MSDOS like
|
||||||
if (filename[0] == wxT('\\') || (wxIsalpha (filename[0]) && filename[1] == wxT(':')))
|
if (filename[0] == wxT('\\') ||
|
||||||
|
(filename.size() > 1 && (wxIsalpha (filename[0]) && filename[1] == wxT(':'))))
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@@ -525,6 +525,12 @@ void FileFunctionsTestCase::IsAbsolutePath()
|
|||||||
CPPUNIT_ASSERT( filename.MakeAbsolute() );
|
CPPUNIT_ASSERT( filename.MakeAbsolute() );
|
||||||
// wxFileName::GetFullPath returns absolute path
|
// wxFileName::GetFullPath returns absolute path
|
||||||
CPPUNIT_ASSERT_MESSAGE( msg, wxIsAbsolutePath(filename.GetFullPath()));
|
CPPUNIT_ASSERT_MESSAGE( msg, wxIsAbsolutePath(filename.GetFullPath()));
|
||||||
|
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
CPPUNIT_ASSERT( wxIsAbsolutePath("\\"));
|
||||||
|
CPPUNIT_ASSERT( wxIsAbsolutePath("c:"));
|
||||||
|
CPPUNIT_ASSERT( !wxIsAbsolutePath("c"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileFunctionsTestCase::PathOnly()
|
void FileFunctionsTestCase::PathOnly()
|
||||||
|
Reference in New Issue
Block a user