Bug Summary

File:home/maarten/src/libreoffice/core/unotest/source/cpp/directories.cxx
Warning:line 36, column 5
Array access (from variable 'pWorkdirRoot') results in a null pointer dereference

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name directories.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D OOO_DLLIMPLEMENTATION_UNOTEST -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/cppunit/include -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/unotest/source/cpp/directories.cxx
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#include <sal/config.h>
11
12#include <cppunit/TestAssert.h>
13#include <osl/file.hxx>
14#include <unotest/directories.hxx>
15
16namespace {
17
18OUString getFileURLFromSystemPath(OUString const & path) {
19 OUString url;
20 osl::FileBase::RC e = osl::FileBase::getFileURLFromSystemPath(path, url);
21 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e)( CppUnit::assertEquals( (osl::FileBase::E_None), (e), CppUnit
::SourceLine( "/home/maarten/src/libreoffice/core/unotest/source/cpp/directories.cxx"
, 21 ), "" ) )
;
22 if (!url.endsWith("/")) {
23 url += "/";
24 }
25 return url;
26}
27
28}
29
30test::Directories::Directories() {
31 const char* pSrcRoot = getenv( "SRC_ROOT" );
32 CPPUNIT_ASSERT_MESSAGE("SRC_ROOT env variable not set", pSrcRoot != nullptr)( CppUnit::Asserter::failIf( !(pSrcRoot != nullptr), CppUnit::
Message( "assertion failed", "Expression: " "pSrcRoot != nullptr"
, CppUnit::message_to_string("SRC_ROOT env variable not set")
), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/unotest/source/cpp/directories.cxx"
, 32 ) ) )
;
1
Assuming the condition is true
33 CPPUNIT_ASSERT_MESSAGE("SRC_ROOT env variable not set", pSrcRoot[0] != 0)( CppUnit::Asserter::failIf( !(pSrcRoot[0] != 0), CppUnit::Message
( "assertion failed", "Expression: " "pSrcRoot[0] != 0", CppUnit
::message_to_string("SRC_ROOT env variable not set") ), CppUnit
::SourceLine( "/home/maarten/src/libreoffice/core/unotest/source/cpp/directories.cxx"
, 33 ) ) )
;
2
Assuming the condition is false
34 const char* pWorkdirRoot = getenv( "WORKDIR_FOR_BUILD" );
3
'pWorkdirRoot' initialized here
35 CPPUNIT_ASSERT_MESSAGE("$WORKDIR_FOR_BUILD env variable not set", pWorkdirRoot != nullptr)( CppUnit::Asserter::failIf( !(pWorkdirRoot != nullptr), CppUnit
::Message( "assertion failed", "Expression: " "pWorkdirRoot != nullptr"
, CppUnit::message_to_string("$WORKDIR_FOR_BUILD env variable not set"
) ), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/unotest/source/cpp/directories.cxx"
, 35 ) ) )
;
4
Assuming pointer value is null
36 CPPUNIT_ASSERT_MESSAGE("$WORKDIR_FOR_BUILD env variable not set", pWorkdirRoot[0] != 0)( CppUnit::Asserter::failIf( !(pWorkdirRoot[0] != 0), CppUnit
::Message( "assertion failed", "Expression: " "pWorkdirRoot[0] != 0"
, CppUnit::message_to_string("$WORKDIR_FOR_BUILD env variable not set"
) ), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/unotest/source/cpp/directories.cxx"
, 36 ) ) )
;
5
Array access (from variable 'pWorkdirRoot') results in a null pointer dereference
37 m_aSrcRootPath = OUString::createFromAscii( pSrcRoot );
38 m_aSrcRootURL = getFileURLFromSystemPath(m_aSrcRootPath);
39
40 m_aWorkdirRootPath = OUString::createFromAscii( pWorkdirRoot );
41 m_aWorkdirRootURL = getFileURLFromSystemPath(m_aWorkdirRootPath);
42}
43
44OUString test::Directories::getURLFromSrc(const OUString& rPath) const
45{
46 return m_aSrcRootURL + rPath;
47}
48
49OUString test::Directories::getPathFromSrc(const OUString& rPath) const
50{
51 return m_aSrcRootPath + rPath;
52}
53
54OUString test::Directories::getURLFromWorkdir(const OUString& rPath) const
55{
56 return m_aWorkdirRootURL + rPath;
57}
58
59OUString test::Directories::getPathFromWorkdir(const OUString& rPath) const
60{
61 return m_aWorkdirRootPath + rPath;
62}
63
64/* vim:set shiftwidth=4 softtabstop=4 expandtab: */