diff options
author | Tomofumi Yagi <yagitmknada@gmail.com> | 2020-10-03 19:16:43 +0900 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2020-10-04 13:23:34 +0200 |
commit | 2a338d521618333a0630a31b46fd0fc9decbe0e5 (patch) | |
tree | a4af39e4ce58a302d4176172143916fdb7da71e6 /sc/source/ui/dbgui | |
parent | ae7f0fc33a9d0d5637a8d1a8feff41330b50c91b (diff) |
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.kaganski@collabora.com>
Diffstat (limited to 'sc/source/ui/dbgui')
-rw-r--r-- | sc/source/ui/dbgui/scuiasciiopt.cxx | 41 |
1 files changed, 22 insertions, 19 deletions
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 ); } |