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 tdf#123936 Formatting files in module sal with clang-format 2020-11-21 13:16:53 +01:00
context.hxx tdf#123936 Formatting files in module sal with clang-format 2020-11-21 13:16:53 +01:00
convertadobe.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
convertbig5hkscs.cxx tdf#146619 Remove unused includes from sal/ [cpp files] 2023-09-19 08:35:12 +02:00
convertbig5hkscs.hxx Revert "loplugin:constfields in reportdesign,sal,sax" 2020-03-12 09:22:20 +01:00
convertbig5hkscs.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
converter.cxx New loplugin:unsignedcompare 2020-01-28 07:42:15 +01:00
converter.hxx compact namespace in sal..svgio 2020-05-10 12:03:13 +02:00
converteuctw.cxx tdf#146619 Remove unused includes from sal/ [cpp files] 2023-09-19 08:35:12 +02:00
converteuctw.hxx loplugin:includeform: sal 2017-10-23 22:45:58 +02:00
converteuctw.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
convertgb18030.cxx tdf#146619 Remove unused includes from sal/ [cpp files] 2023-09-19 08:35:12 +02:00
convertgb18030.hxx Revert "loplugin:constfields in reportdesign,sal,sax" 2020-03-12 09:22:20 +01:00
convertgb18030.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
convertisciidevangari.cxx tdf#146619 Remove unused includes from sal/ [cpp files] 2023-09-19 08:35:12 +02:00
convertisciidevangari.hxx fdo#68849: Add header guards to all include files 2014-06-01 16:07:41 +00:00
convertisciidevangari.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
convertiso2022cn.cxx tdf#146619 Remove unused includes from sal/ [cpp files] 2023-09-19 08:35:12 +02:00
convertiso2022cn.hxx loplugin:includeform: sal 2017-10-23 22:45:58 +02:00
convertiso2022cn.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
convertiso2022jp.cxx tdf#146619 Remove unused includes from sal/ [cpp files] 2023-09-19 08:35:12 +02:00
convertiso2022jp.hxx loplugin:includeform: sal 2017-10-23 22:45:58 +02:00
convertiso2022jp.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
convertiso2022kr.cxx tdf#146619 Remove unused includes from sal/ [cpp files] 2023-09-19 08:35:12 +02:00
convertiso2022kr.hxx loplugin:includeform: sal 2017-10-23 22:45:58 +02:00
convertiso2022kr.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
convertsimple.cxx Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
convertsimple.hxx compact namespace in sal..svgio 2020-05-10 12:03:13 +02:00
convertsinglebytetobmpunicode.cxx tdf#146619 Remove unused includes from sal/ [cpp files] 2023-09-19 08:35:12 +02:00
convertsinglebytetobmpunicode.hxx compact namespace in sal..svgio 2020-05-10 12:03:13 +02:00
gettextencodingdata.hxx tdf#123936 Formatting files in module sal with clang-format 2020-11-21 13:16:53 +01:00
handleundefinedunicodetotextchar.cxx tdf#146619 Remove unused includes from sal/ [headers] 2023-08-14 09:10:29 +02:00
handleundefinedunicodetotextchar.hxx compact namespace in sal..svgio 2020-05-10 12:03:13 +02:00
tables.cxx tdf#146619 Remove unused includes from sal/ [headers] 2023-08-14 09:10:29 +02:00
tcvtarb1.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
tcvtbyte.cxx More loplugin:cstylecast: sal 2018-01-12 20:17:51 +01:00
tcvtbyte.hxx loplugin:includeform: sal 2017-10-23 22:45:58 +02:00
tcvteas1.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
tcvtest1.tab tdf#150877: Add support for Kamenický and Mazovia encodings 2022-09-15 15:56:35 +02:00
tcvtjp1.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtjp2.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtjp3.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtjp4.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtjp5.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtjp6.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
tcvtkr1.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtkr2.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtkr4.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtkr5.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtkr6.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
tcvtlat1.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
tcvtmb.cxx Fix conversion of U+0000 in ImplUnicodeToDBCS 2019-09-05 11:11:29 +02:00
tcvtscn1.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtscn2.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtscn3.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtscn4.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtscn5.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtscn6.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
tcvtsym1.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
tcvttcn1.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvttcn2.tab Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvttcn6.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
tcvtuni1.tab clang:optin.performance.Padding in sal 2021-09-10 18:13:57 +02:00
tcvtutf7.cxx Upcoming improved loplugin:staticanonymous -> redundantstatic: sal 2020-07-02 07:09:56 +02:00
tcvtutf8.cxx Properly fix use of uninitialized value 2024-05-29 12:08:43 +02:00
tcvtutf8.hxx loplugin:includeform: sal 2017-10-23 22:45:58 +02:00
tenchelp.hxx tdf#146619 Remove unused includes from sal/ [headers] 2023-08-14 09:10:29 +02:00
tencinfo.cxx tdf#146619 Remove unused includes from sal/ [cpp files] 2023-09-19 08:35:12 +02:00
textcvt.cxx sal_Char->char in remotebridges..sax 2019-12-19 19:17:57 +01:00
textenc.cxx tdf#146619 Remove unused includes from sal/ [cpp files] 2023-09-19 08:35:12 +02:00
unichars.cxx tdf#123936 Formatting files in module sal with clang-format 2020-11-21 13:16:53 +01:00
unichars.hxx tdf#146619 Remove unused includes from sal/ [headers] 2023-08-14 09:10:29 +02:00