sal/textenc/tcvtutf8.cxx |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

New commits:
commit 00914176b1cd056b99f66182ffb00c0f1a123d8c
Author:     Stephan Bergmann <stephan.bergm...@allotropia.de>
AuthorDate: Wed May 29 10:01:13 2024 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Thu May 30 09:56:18 2024 +0200

    Properly fix use of uninitialized value
    
    Following up on 66322c5f4a5465c74fa3ceefaa2f76e86a277c16 "Silence warning 
C4701:
    potentially uninitialized local variable" (which had apparently wrongly 
assumed
    that that MSVC warning was a false positive) and
    b1a6bd87b803f760f5bf0e2b7bc519b3b2fbfa4e "ofz: Use-of-uninitialized-value in
    ImplConvertUtf8ToUnicode", which had demonstrated that this was indeed a 
true
    positive, as per the comment at
    
<https://gerrit.libreoffice.org/c/core/+/168079/2#message-8b941c986658cb41641c0a317937bd0d3574e0b9>
    "ofz: Use-of-uninitialized-value in ImplConvertUtf8ToUnicode", and which 
could
    also be observed with a local patch of
    
    > diff --git a/sal/textenc/tcvtutf8.cxx b/sal/textenc/tcvtutf8.cxx
    > index 05290cc204fd..319acd41c627 100644
    > --- a/sal/textenc/tcvtutf8.cxx
    > +++ b/sal/textenc/tcvtutf8.cxx
    > @@ -56,7 +56,7 @@ void ImplResetUtf8ToUnicodeContext(void * pContext)
    >  {
    >      if (pContext != nullptr)
    >      {
    > -        static_cast< ImplUtf8ToUnicodeContext * >(pContext)->nBytes = 
int();
    > +        static_cast< ImplUtf8ToUnicodeContext * >(pContext)->nBytes = 
1234;
    >          static_cast< ImplUtf8ToUnicodeContext * >(pContext)->nShift = -1;
    >          static_cast< ImplUtf8ToUnicodeContext * >(pContext)->bCheckBom = 
true;
    >      }
    > @@ -74,7 +74,7 @@ sal_Size ImplConvertUtf8ToUnicode(
    >  {
    >      bool bJavaUtf8 = pData != nullptr;
    >      sal_uInt32 nUtf32 = 0;
    > -    int nBytes = int();
    > +    int nBytes = 1234;
    >      int nShift = -1;
    >      bool bCheckBom = true;
    >      sal_uInt32 nInfo = 0;
    > @@ -208,6 +208,7 @@ sal_Size ImplConvertUtf8ToUnicode(
    >          continue;
    >
    >      bad_input:
    > +        assert(nBytes != 1234);
    >          switch 
(sal::detail::textenc::handleBadInputTextToUnicodeConversion(
    >                      false, nBytes != 1, 0, nFlags, &pDestBufPtr, 
pDestBufEnd,
    >                      &nInfo))
    
    and seeing CppunitTest_sal_rtl CPPUNIT_TEST_NAME=Test::testInvalidUtf8 fail 
by
    hitting that assert.
    
    So initialize nBytes to 1 to make that bad_input scenario call
    handleBadInputTextToUnicodeConversion with a bMultiByte=false argument.
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168181
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>
    (cherry picked from commit 73eed7cfe08624227214378c50e2f09c9a868ee3)
    Conflicts:
            sal/textenc/tcvtutf8.cxx
    
    Change-Id: Ib8a326d497071f4249169e9d4f5871f06cfccbdf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168185
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sal/textenc/tcvtutf8.cxx b/sal/textenc/tcvtutf8.cxx
index 456d77e2f51c..2d73a96a3c50 100644
--- a/sal/textenc/tcvtutf8.cxx
+++ b/sal/textenc/tcvtutf8.cxx
@@ -56,6 +56,7 @@ void ImplResetUtf8ToUnicodeContext(void * pContext)
 {
     if (pContext != nullptr)
     {
+        static_cast< ImplUtf8ToUnicodeContext * >(pContext)->nBytes = 1;
         static_cast< ImplUtf8ToUnicodeContext * >(pContext)->nShift = -1;
         static_cast< ImplUtf8ToUnicodeContext * >(pContext)->bCheckBom = true;
     }
@@ -73,7 +74,7 @@ sal_Size ImplConvertUtf8ToUnicode(
 {
     bool bJavaUtf8 = pData != nullptr;
     sal_uInt32 nUtf32 = 0;
-    int nBytes = int();
+    int nBytes = 1;
     int nShift = -1;
     bool bCheckBom = true;
     sal_uInt32 nInfo = 0;

Reply via email to