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, strTest,
strDesc, strDesc,
curField; // accumulator curField; // accumulator
for ( bool cont = TRUE; cont; pc++ ) { bool cont = TRUE;
while ( cont ) {
switch ( *pc ) { switch ( *pc ) {
case wxT('\\'): case wxT('\\'):
// interpret the next character literally (notice that // interpret the next character literally (notice that
// backslash can be used for line continuation) // backslash can be used for line continuation)
if ( *++pc == wxT('\0') ) { 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 wxLogDebug(wxT("Mailcap file %s, line %d: "
// pc++ in the for line it will point to the beginning "'\\' on the end of the last line "
// of the next line in the file "ignored."),
pc = file[++nLine].c_str() - 1; 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 { else {
// just a normal character // just a normal character
@@ -1505,6 +1518,12 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
switch ( currentToken ) { switch ( currentToken ) {
case Field_Type: case Field_Type:
strType = curField; 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 ) { if ( strType.Find(wxT('/')) == wxNOT_FOUND ) {
// we interpret "type" as "type/*" // we interpret "type" as "type/*"
strType += wxT("/*"); strType += wxT("/*");
@@ -1520,7 +1539,7 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
break; break;
case Field_Other: case Field_Other:
{ if ( !curField.empty() ) {
// "good" mailcap entry? // "good" mailcap entry?
bool ok = TRUE; 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 // it already has this value
//currentToken = Field_Other; //currentToken = Field_Other;
@@ -1611,6 +1631,9 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
default: default:
curField += *pc; curField += *pc;
} }
// continue in the same line
pc++;
} }
// check that we really read something reasonable // check that we really read something reasonable