office-gobmx/sal
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
..
android
cppunittester tdf#146619 Remove unused includes from sal/ [cpp files] 2023-09-19 08:35:12 +02:00
emscripten
inc osl_get_system_random_data should return bool 2024-02-11 13:16:07 +01:00
osl we dereference pProfile->m_Lines on the next line anyway 2024-04-30 13:41:19 +02:00
qa Unit test for tdf#160985 2024-05-15 18:02:32 +02:00
rtl Resolves: tdf#160985 Max integer representation for rtl_math_StringFormat_G 2024-05-15 18:02:19 +02:00
test
textenc Properly fix use of uninitialized value 2024-05-29 12:08:43 +02:00
util
CompilerTest_sal_rtl_oustring.mk
CppunitTest_Module_DLL.mk
CppunitTest_sal_comtools.mk
CppunitTest_sal_osl.mk Use less boost_headers in sal 2023-08-12 13:24:34 +02:00
CppunitTest_sal_osl_security.mk
CppunitTest_sal_retry_if_failed.mk
CppunitTest_sal_rtl.mk Use less boost_headers in sal 2023-08-12 13:24:34 +02:00
CppunitTest_sal_types.mk
Executable_cppunittester.mk Use consistent conditions in code and makefile 2024-03-21 08:05:03 +01:00
Executable_osl_process_child.mk
IwyuFilter_sal.yaml tdf#146619 Remove unused includes from sal/ [cpp files] 2023-09-19 08:35:12 +02:00
Library_lo-bootstrap.mk
Library_sal.mk Move some stuff from path_helper to file_dirvol, and simplify 2024-02-20 10:25:59 +01:00
Library_sal_textenc.mk Use less boost_headers in sal 2023-08-12 13:24:34 +02:00
Makefile
Module_sal.mk
README.md

System Abstraction Layer (SAL)

System abstraction layer; rtl, osl and sal

rtl: Platform independent strings

osl: platform specific stuff, threads, dynamic loading, process, ipc, etc

Exports only C API and some inline-methods (only C++ API).