sc/source/ui/dbgui/scuiasciiopt.cxx |   41 +++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 19 deletions(-)

New commits:
commit 2a338d521618333a0630a31b46fd0fc9decbe0e5
Author:     Tomofumi Yagi <yagitmkn...@gmail.com>
AuthorDate: Sat Oct 3 19:16:43 2020 +0900
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Oct 4 13:23:34 2020 +0200

    sc: ucsdet_detect may return nullptr
    
    ucsdet_detect function needs a NULL checking of the return value.
    
    "a UCharsetMatch representing the best matching charset, or NULL if no 
charset
    matches the byte data."
    
    Change-Id: I7e9a4b03ffd3c5e3f4953c2c7964dc67a53c39b5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103890
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sc/source/ui/dbgui/scuiasciiopt.cxx 
b/sc/source/ui/dbgui/scuiasciiopt.cxx
index bfc154bffc08..be524ab15437 100644
--- a/sc/source/ui/dbgui/scuiasciiopt.cxx
+++ b/sc/source/ui/dbgui/scuiasciiopt.cxx
@@ -394,28 +394,31 @@ ScImportAsciiDlg::ScImportAsciiDlg(weld::Window* pParent, 
const OUString& aDatNa
             UErrorCode uerr = U_ZERO_ERROR;
             UCharsetDetector* ucd = ucsdet_open( &uerr );
             ucsdet_setText( ucd, reinterpret_cast<const char*>(bytes), nRead, 
&uerr );
-            const UCharsetMatch* match = ucsdet_detect( ucd, &uerr );
-            const char* pEncodingName = ucsdet_getName( match, &uerr );
 
-            if ( U_SUCCESS(uerr) && !strcmp("UTF-8", pEncodingName) )
+            if ( const UCharsetMatch* match = ucsdet_detect(ucd, &uerr) )
             {
-                ePreselectUnicode = RTL_TEXTENCODING_UTF8; // UTF-8
-                mpDatStream->StartReadingUnicodeText( RTL_TEXTENCODING_UTF8 );
+                const char* pEncodingName = ucsdet_getName( match, &uerr );
+
+                if ( U_SUCCESS(uerr) && !strcmp("UTF-8", pEncodingName) )
+                {
+                    ePreselectUnicode = RTL_TEXTENCODING_UTF8; // UTF-8
+                    mpDatStream->StartReadingUnicodeText( 
RTL_TEXTENCODING_UTF8 );
+                }
+                else if ( U_SUCCESS(uerr) && !strcmp("UTF-16LE", 
pEncodingName) )
+                {
+                    ePreselectUnicode = RTL_TEXTENCODING_UNICODE; // UTF-16LE
+                    mpDatStream->SetEndian( SvStreamEndian::LITTLE );
+                    mpDatStream->StartReadingUnicodeText( 
RTL_TEXTENCODING_UNICODE );
+                }
+                else if ( U_SUCCESS(uerr) && !strcmp("UTF-16BE", 
pEncodingName) )
+                {
+                    ePreselectUnicode = RTL_TEXTENCODING_UNICODE; // UTF-16BE
+                    mpDatStream->SetEndian( SvStreamEndian::BIG );
+                    mpDatStream->StartReadingUnicodeText( 
RTL_TEXTENCODING_UNICODE );
+                }
+                else // other
+                    mpDatStream->StartReadingUnicodeText( 
RTL_TEXTENCODING_DONTKNOW );
             }
-            else if ( U_SUCCESS(uerr) && !strcmp("UTF-16LE", pEncodingName) )
-            {
-                ePreselectUnicode = RTL_TEXTENCODING_UNICODE; // UTF-16LE
-                mpDatStream->SetEndian( SvStreamEndian::LITTLE );
-                mpDatStream->StartReadingUnicodeText( RTL_TEXTENCODING_UNICODE 
);
-            }
-            else if ( U_SUCCESS(uerr) && !strcmp("UTF-16BE", pEncodingName) )
-            {
-                ePreselectUnicode = RTL_TEXTENCODING_UNICODE; // UTF-16BE
-                mpDatStream->SetEndian(SvStreamEndian::BIG);
-                mpDatStream->StartReadingUnicodeText( RTL_TEXTENCODING_UNICODE 
);
-            }
-            else // other
-                mpDatStream->StartReadingUnicodeText( 
RTL_TEXTENCODING_DONTKNOW );
 
             ucsdet_close( ucd );
         }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to