[Libreoffice-commits] core.git: 2 commits - svtools/source tools/source

Tamás Zolnai (via logerrit) logerrit at kemper.freedesktop.org
Sat Dec 7 21:15:45 UTC 2019


 svtools/source/svrtf/parrtf.cxx |    5 +--
 tools/source/inet/inetmime.cxx  |   62 +---------------------------------------
 2 files changed, 6 insertions(+), 61 deletions(-)

New commits:
commit c4d3d5a753adc005c34aee3f7f81df4c36d3e261
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Sat Dec 7 19:21:34 2019 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Sat Dec 7 22:15:06 2019 +0100

    clang-tidy(WIP): bugprone-signed-char-misuse findings 3
    
    Convert char to unsigned char first in some found use cases.
    In these cases the chart is converted to an unsigned integer,
    so characters with negativ values would be converted to wierd
    values around the maximum value of sal_uInt32.
    
    Change-Id: I5570b414ff9c0178222ec40830b490824d8abb07
    Reviewed-on: https://gerrit.libreoffice.org/84690
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/svtools/source/svrtf/parrtf.cxx b/svtools/source/svrtf/parrtf.cxx
index c3a43bf8a34d..8a83512c06ae 100644
--- a/svtools/source/svrtf/parrtf.cxx
+++ b/svtools/source/svrtf/parrtf.cxx
@@ -386,7 +386,7 @@ void SvRTFParser::ScanText()
                             if (nSlash != '\\' || nNextCh != '\'')
                             {
                                 rInput.SeekRel(-1);
-                                nNextCh = nSlash;
+                                nNextCh = static_cast<unsigned char>(nSlash);
                                 break;
                             }
                         }
@@ -582,7 +582,8 @@ SvParserState SvRTFParser::CallParser()
 {
     sal_Char cFirstCh;
     nNextChPos = rInput.Tell();
-    rInput.ReadChar( cFirstCh ); nNextCh = cFirstCh;
+    rInput.ReadChar( cFirstCh );
+    nNextCh = static_cast<unsigned char>(cFirstCh);
     eState = SvParserState::Working;
     nOpenBrakets = 0;
     eCodeSet = RTL_TEXTENCODING_MS_1252;
diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx
index 0eab4528c8eb..b96e463154e4 100644
--- a/tools/source/inet/inetmime.cxx
+++ b/tools/source/inet/inetmime.cxx
@@ -1272,7 +1272,7 @@ OUString INetMIME::decodeHeaderFieldBody(const OString& rBody)
                         }
                         else
                         {
-                            sal_uInt32 nChar = *q++;
+                            sal_uInt32 nChar = static_cast<unsigned char>(*q++);
                             switch (nChar)
                             {
                                 case '=':
commit ec1795c654cc7a1ae7f7eed0db0588e206346c11
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Sat Dec 7 19:07:30 2019 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Sat Dec 7 22:14:50 2019 +0100

    clang-tidy(WIP): bugprone-signed-char-misuse findings 2
    
    The caughed code is actually unused, so remove it.
    
    Change-Id: I82c21cef7e125087f167ccb571a9f8efe1aa548c
    Reviewed-on: https://gerrit.libreoffice.org/84689
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx
index f974c911013c..0eab4528c8eb 100644
--- a/tools/source/inet/inetmime.cxx
+++ b/tools/source/inet/inetmime.cxx
@@ -131,46 +131,6 @@ std::unique_ptr<sal_Unicode[]> convertToUnicode(const sal_Char * pBegin,
     return pBuffer;
 }
 
-std::unique_ptr<sal_Char[]> convertFromUnicode(const sal_Unicode * pBegin,
-                                        const sal_Unicode * pEnd,
-                                        rtl_TextEncoding eEncoding,
-                                        sal_Size & rSize)
-{
-    if (eEncoding == RTL_TEXTENCODING_DONTKNOW)
-        return nullptr;
-    rtl_UnicodeToTextConverter hConverter
-        = rtl_createUnicodeToTextConverter(eEncoding);
-    rtl_UnicodeToTextContext hContext
-        = rtl_createUnicodeToTextContext(hConverter);
-    std::unique_ptr<sal_Char[]> pBuffer;
-    sal_uInt32 nInfo;
-    for (sal_Size nBufferSize = pEnd - pBegin;;
-         nBufferSize += nBufferSize / 3 + 1)
-    {
-        pBuffer.reset(new sal_Char[nBufferSize]);
-        sal_Size nSrcCvtBytes;
-        rSize = rtl_convertUnicodeToText(
-                    hConverter, hContext, pBegin, pEnd - pBegin, pBuffer.get(),
-                    nBufferSize,
-                    RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
-                        | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
-                        | RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE
-                        | RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR,
-                    &nInfo, &nSrcCvtBytes);
-        if (nInfo != RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL)
-            break;
-        pBuffer.reset();
-        rtl_resetUnicodeToTextContext(hConverter, hContext);
-    }
-    rtl_destroyUnicodeToTextContext(hConverter, hContext);
-    rtl_destroyUnicodeToTextConverter(hConverter);
-    if (nInfo != 0)
-    {
-        pBuffer.reset();
-    }
-    return pBuffer;
-}
-
 /** Put the UTF-16 encoding of a UTF-32 character into a buffer.
 
     @param pBuffer  Points to a buffer, must not be null.
@@ -231,7 +191,6 @@ void writeUTF8(OStringBuffer & rSink, sal_uInt32 nChar)
 
 bool translateUTF8Char(const sal_Char *& rBegin,
                                  const sal_Char * pEnd,
-                                 rtl_TextEncoding eEncoding,
                                  sal_uInt32 & rCharacter)
 {
     if (rBegin == pEnd || static_cast< unsigned char >(*rBegin) < 0x80
@@ -283,21 +242,7 @@ bool translateUTF8Char(const sal_Char *& rBegin,
     if (!rtl::isUnicodeCodePoint(nUCS4) || nUCS4 < nMin)
         return false;
 
-    if (eEncoding >= RTL_TEXTENCODING_UCS4)
-        rCharacter = nUCS4;
-    else
-    {
-        sal_Unicode aUTF16[2];
-        const sal_Unicode * pUTF16End = putUTF32Character(aUTF16, nUCS4);
-        sal_Size nSize;
-        std::unique_ptr<sal_Char[]> pBuffer = convertFromUnicode(aUTF16, pUTF16End, eEncoding,
-                                                nSize);
-        if (!pBuffer)
-            return false;
-        DBG_ASSERT(nSize == 1,
-                   "translateUTF8Char(): Bad conversion");
-        rCharacter = pBuffer[0];
-    }
+    rCharacter = nUCS4;
     rBegin = p;
     return true;
 }
@@ -1442,8 +1387,7 @@ OUString INetMIME::decodeHeaderFieldBody(const OString& rBody)
                 const sal_Char * pUTF8Begin = p - 1;
                 const sal_Char * pUTF8End = pUTF8Begin;
                 sal_uInt32 nCharacter = 0;
-                if (translateUTF8Char(pUTF8End, pEnd, RTL_TEXTENCODING_UCS4,
-                                      nCharacter))
+                if (translateUTF8Char(pUTF8End, pEnd, nCharacter))
                 {
                     appendISO88591(sDecoded, pCopyBegin, p - 1);
                     sal_Unicode aUTF16Buf[2];


More information about the Libreoffice-commits mailing list