office-gobmx/sal/textenc
Stephan Bergmann 73eed7cfe0 Properly fix use of uninitialized value
Following up on 66322c5f4a "Silence warning C4701:
potentially uninitialized local variable" (which had apparently wrongly assumed
that that MSVC warning was a false positive) and
b1a6bd87b8 "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.

Change-Id: Ib8a326d497071f4249169e9d4f5871f06cfccbdf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168181
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-05-29 12:08:43 +02:00
..
generate
context.cxx
context.hxx
convertadobe.tab
convertbig5hkscs.cxx
convertbig5hkscs.hxx
convertbig5hkscs.tab
converter.cxx
converter.hxx
converteuctw.cxx
converteuctw.hxx
converteuctw.tab
convertgb18030.cxx
convertgb18030.hxx
convertgb18030.tab
convertisciidevangari.cxx
convertisciidevangari.hxx
convertisciidevangari.tab
convertiso2022cn.cxx
convertiso2022cn.hxx
convertiso2022cn.tab
convertiso2022jp.cxx
convertiso2022jp.hxx
convertiso2022jp.tab
convertiso2022kr.cxx
convertiso2022kr.hxx
convertiso2022kr.tab
convertsimple.cxx
convertsimple.hxx
convertsinglebytetobmpunicode.cxx
convertsinglebytetobmpunicode.hxx
gettextencodingdata.hxx
handleundefinedunicodetotextchar.cxx
handleundefinedunicodetotextchar.hxx
tables.cxx
tcvtarb1.tab
tcvtbyte.cxx
tcvtbyte.hxx
tcvteas1.tab
tcvtest1.tab
tcvtjp1.tab
tcvtjp2.tab
tcvtjp3.tab
tcvtjp4.tab
tcvtjp5.tab
tcvtjp6.tab
tcvtkr1.tab
tcvtkr2.tab
tcvtkr4.tab
tcvtkr5.tab
tcvtkr6.tab
tcvtlat1.tab
tcvtmb.cxx
tcvtscn1.tab
tcvtscn2.tab
tcvtscn3.tab
tcvtscn4.tab
tcvtscn5.tab
tcvtscn6.tab
tcvtsym1.tab
tcvttcn1.tab
tcvttcn2.tab
tcvttcn6.tab
tcvtuni1.tab
tcvtutf7.cxx
tcvtutf8.cxx
tcvtutf8.hxx
tenchelp.hxx
tencinfo.cxx
textcvt.cxx
textenc.cxx
unichars.cxx
unichars.hxx