fixed crash with '\' on the end of the last line

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9346 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2001-02-12 00:51:17 +00:00
parent e70d4ce8d6
commit 6e358ae704

View File

@ -1472,18 +1472,31 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
strTest,
strDesc,
curField; // accumulator
for ( bool cont = TRUE; cont; pc++ ) {
bool cont = TRUE;
while ( cont ) {
switch ( *pc ) {
case wxT('\\'):
// interpret the next character literally (notice that
// backslash can be used for line continuation)
if ( *++pc == wxT('\0') ) {
// fetch the next line.
// fetch the next line if there is one
if ( nLine == nLineCount - 1 ) {
// something is wrong, bail out
cont = FALSE;
// pc currently points to nowhere, but after the next
// pc++ in the for line it will point to the beginning
// of the next line in the file
pc = file[++nLine].c_str() - 1;
wxLogDebug(wxT("Mailcap file %s, line %d: "
"'\\' on the end of the last line "
"ignored."),
strFileName.c_str(),
nLine + 1);
}
else {
// pass to the beginning of the next line
pc = file[++nLine].c_str();
// skip pc++ at the end of the loop
continue;
}
}
else {
// just a normal character
@ -1505,6 +1518,12 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
switch ( currentToken ) {
case Field_Type:
strType = curField;
if ( strType.empty() ) {
// I don't think that this is a valid mailcap
// entry, but try to interpret it somehow
strType = _T('*');
}
if ( strType.Find(wxT('/')) == wxNOT_FOUND ) {
// we interpret "type" as "type/*"
strType += wxT("/*");
@ -1520,7 +1539,7 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
break;
case Field_Other:
{
if ( !curField.empty() ) {
// "good" mailcap entry?
bool ok = TRUE;
@ -1595,6 +1614,7 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
}
}
}
//else: the field is empty, ignore silently
// it already has this value
//currentToken = Field_Other;
@ -1611,6 +1631,9 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
default:
curField += *pc;
}
// continue in the same line
pc++;
}
// check that we really read something reasonable