Bug Summary

File:home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx
Warning:line 197, column 27
Called C++ object pointer is null

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 docbasic.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 -isystem /usr/include/libxml2 -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 SW_DLLIMPLEMENTATION -D SWUI_DLL_NAME="libswuilo.so" -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/sw/source/core/inc -I /home/maarten/src/libreoffice/core/sw/source/filter/inc -I /home/maarten/src/libreoffice/core/sw/source/uibase/inc -I /home/maarten/src/libreoffice/core/sw/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/sw/sdi -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/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/sw/generated -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/oovbaapi/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/sw/source/core/doc/docbasic.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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <hintids.hxx>
21
22#include <rtl/ustring.hxx>
23#include <sal/log.hxx>
24#include <vcl/imap.hxx>
25#include <vcl/imapobj.hxx>
26#include <basic/sbx.hxx>
27#include <frmfmt.hxx>
28#include <fmtinfmt.hxx>
29#include <fmturl.hxx>
30#include <frmatr.hxx>
31#include <docary.hxx>
32#include <doc.hxx>
33#include <docsh.hxx>
34#include <swevent.hxx>
35#include <frameformats.hxx>
36#include <memory>
37
38using namespace ::com::sun::star::uno;
39
40static Sequence<Any> *lcl_docbasic_convertArgs( SbxArray& rArgs )
41{
42 Sequence<Any> *pRet = nullptr;
43
44 sal_uInt32 nCount = rArgs.Count32();
45 if( nCount > 1 )
46 {
47 nCount--;
48 pRet = new Sequence<Any>( nCount );
49 Any *pUnoArgs = pRet->getArray();
50 for( sal_uInt32 i=0; i<nCount; i++ )
51 {
52 SbxVariable *pVar = rArgs.Get32( i+1 );
53 switch( pVar->GetType() )
54 {
55 case SbxSTRING:
56 pUnoArgs[i] <<= pVar->GetOUString();
57 break;
58 case SbxCHAR:
59 pUnoArgs[i] <<= static_cast<sal_Int16>(pVar->GetChar()) ;
60 break;
61 case SbxUSHORT:
62 pUnoArgs[i] <<= static_cast<sal_Int16>(pVar->GetUShort());
63 break;
64 case SbxLONG:
65 pUnoArgs[i] <<= pVar->GetLong();
66 break;
67 default:
68 pUnoArgs[i].clear();
69 break;
70 }
71 }
72 }
73
74 return pRet;
75}
76
77void SwDoc::ExecMacro( const SvxMacro& rMacro, OUString* pRet, SbxArray* pArgs )
78{
79 switch( rMacro.GetScriptType() )
80 {
81 case STARBASIC:
82 {
83 SbxBaseRef aRef;
84 SbxValue* pRetValue = new SbxValue;
85 aRef = pRetValue;
86 mpDocShell->CallBasic( rMacro.GetMacName(),
87 rMacro.GetLibName(),
88 pArgs, pRet ? pRetValue : nullptr );
89
90 if( pRet && SbxNULL < pRetValue->GetType() &&
91 SbxVOID != pRetValue->GetType() )
92 {
93 // valid value, so set it
94 *pRet = pRetValue->GetOUString();
95 }
96 }
97 break;
98 case JAVASCRIPT:
99 // ignore JavaScript calls
100 break;
101 case EXTENDED_STYPE:
102 {
103 std::unique_ptr<Sequence<Any> > pUnoArgs;
104 if( pArgs )
105 {
106 // better to rename the local function to lcl_translateBasic2Uno and
107 // a much shorter routine can be found in sfx2/source/doc/objmisc.cxx
108 pUnoArgs.reset(lcl_docbasic_convertArgs( *pArgs ));
109 }
110
111 if (!pUnoArgs)
112 {
113 pUnoArgs.reset(new Sequence< Any > (0));
114 }
115
116 // TODO - return value is not handled
117 Any aRet;
118 Sequence< sal_Int16 > aOutArgsIndex;
119 Sequence< Any > aOutArgs;
120
121 SAL_INFO("sw", "SwDoc::ExecMacro URL is " << rMacro.GetMacName() )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "sw")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "SwDoc::ExecMacro URL is " << rMacro.GetMacName
()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), (
"sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx"
":" "121" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "SwDoc::ExecMacro URL is " << rMacro
.GetMacName()), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "SwDoc::ExecMacro URL is " <<
rMacro.GetMacName(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx"
":" "121" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "SwDoc::ExecMacro URL is " << rMacro.GetMacName
()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), (
"sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx"
":" "121" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "SwDoc::ExecMacro URL is " << rMacro
.GetMacName()), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "SwDoc::ExecMacro URL is " <<
rMacro.GetMacName(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx"
":" "121" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
122
123 mpDocShell->CallXScript(
124 rMacro.GetMacName(), *pUnoArgs, aRet, aOutArgsIndex, aOutArgs);
125
126 break;
127 }
128 }
129}
130
131sal_uInt16 SwDoc::CallEvent( SvMacroItemId nEvent, const SwCallMouseEvent& rCallEvent,
132 bool bCheckPtr )
133{
134 if( !mpDocShell ) // we can't do that without a DocShell!
1
Assuming field 'mpDocShell' is non-null
2
Taking false branch
135 return 0;
136
137 sal_uInt16 nRet = 0;
138 const SvxMacroTableDtor* pTable = nullptr;
139 switch( rCallEvent.eType )
3
Control jumps to 'case EVENT_OBJECT_IMAGEMAP:' at line 176
140 {
141 case EVENT_OBJECT_INETATTR:
142 if( bCheckPtr )
143 {
144 for (const SfxPoolItem* pItem : GetAttrPool().GetItemSurrogates(RES_TXTATR_INETFMT))
145 {
146 auto pFormatItem = dynamic_cast<const SwFormatINetFormat*>(pItem);
147 if( pFormatItem && rCallEvent.PTR.pINetAttr == pFormatItem )
148 {
149 bCheckPtr = false; // misuse as a flag
150 break;
151 }
152 }
153 }
154 if( !bCheckPtr )
155 pTable = rCallEvent.PTR.pINetAttr->GetMacroTable();
156 break;
157
158 case EVENT_OBJECT_URLITEM:
159 case EVENT_OBJECT_IMAGE:
160 {
161 const SwFrameFormat* pFormat = rCallEvent.PTR.pFormat;
162 if( bCheckPtr )
163 {
164 if (GetSpzFrameFormats()->IsAlive(pFormat))
165 bCheckPtr = false; // misuse as a flag
166 else
167 // this shouldn't be possible now that SwCallMouseEvent
168 // listens for dying format?
169 assert(false)(static_cast <bool> (false) ? void (0) : __assert_fail (
"false", "/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx"
, 169, __extension__ __PRETTY_FUNCTION__))
;
170 }
171 if( !bCheckPtr )
172 pTable = &pFormat->GetMacro().GetMacroTable();
173 }
174 break;
175
176 case EVENT_OBJECT_IMAGEMAP:
177 {
178 const IMapObject* pIMapObj = rCallEvent.PTR.IMAP.pIMapObj;
4
'pIMapObj' initialized here
179 if( bCheckPtr )
5
Assuming 'bCheckPtr' is true
6
Taking true branch
180 {
181 const SwFrameFormat* pFormat = rCallEvent.PTR.IMAP.pFormat;
182 if (GetSpzFrameFormats()->IsAlive(pFormat))
7
Assuming the condition is true
8
Taking true branch
183 {
184 const ImageMap* pIMap = pFormat->GetURL().GetMap();
185 if (pIMap)
9
Assuming 'pIMap' is non-null
10
Taking true branch
186 {
187 for( size_t nPos = pIMap->GetIMapObjectCount(); nPos; )
11
Loop condition is true. Entering loop body
188 if( pIMapObj == pIMap->GetIMapObject( --nPos ))
12
Assuming pointer value is null
13
Taking true branch
189 {
190 bCheckPtr = false; // misuse as a flag
191 break;
14
Execution continues on line 196
192 }
193 }
194 }
195 }
196 if( !bCheckPtr
14.1
'bCheckPtr' is false
)
15
Taking true branch
197 pTable = &pIMapObj->GetMacroTable();
16
Called C++ object pointer is null
198 }
199 break;
200 default:
201 break;
202 }
203
204 if( pTable )
205 {
206 nRet = 0x1;
207 if( pTable->IsKeyValid( nEvent ) )
208 {
209 const SvxMacro& rMacro = *pTable->Get( nEvent );
210 if( STARBASIC == rMacro.GetScriptType() )
211 {
212 nRet += ERRCODE_NONEErrCode(0) == mpDocShell->CallBasic( rMacro.GetMacName(),
213 rMacro.GetLibName(), nullptr ) ? 1 : 0;
214 }
215 else if( EXTENDED_STYPE == rMacro.GetScriptType() )
216 {
217 std::unique_ptr<Sequence<Any> > pUnoArgs(new Sequence<Any>());
218
219 Any aRet;
220 Sequence< sal_Int16 > aOutArgsIndex;
221 Sequence< Any > aOutArgs;
222
223 SAL_INFO("sw", "SwDoc::CallEvent URL is " << rMacro.GetMacName() )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "sw")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "SwDoc::CallEvent URL is " << rMacro.GetMacName
()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), (
"sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx"
":" "223" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "SwDoc::CallEvent URL is " << rMacro
.GetMacName()), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "SwDoc::CallEvent URL is " <<
rMacro.GetMacName(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx"
":" "223" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "SwDoc::CallEvent URL is " << rMacro.GetMacName
()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), (
"sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx"
":" "223" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "SwDoc::CallEvent URL is " << rMacro
.GetMacName()), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "SwDoc::CallEvent URL is " <<
rMacro.GetMacName(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx"
":" "223" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
224
225 nRet += ERRCODE_NONEErrCode(0) == mpDocShell->CallXScript(
226 rMacro.GetMacName(), *pUnoArgs,aRet, aOutArgsIndex, aOutArgs) ? 1 : 0;
227 }
228 // JavaScript calls are ignored
229 }
230 }
231 return nRet;
232}
233
234/* vim:set shiftwidth=4 softtabstop=4 expandtab: */