From 6e358ae7043a7a3b1912435f88ad05d796c1bf98 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 12 Feb 2001 00:51:17 +0000 Subject: [PATCH] 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 --- src/unix/mimetype.cpp | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/unix/mimetype.cpp b/src/unix/mimetype.cpp index ff2bb4218a..05bb2f89ab 100644 --- a/src/unix/mimetype.cpp +++ b/src/unix/mimetype.cpp @@ -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