clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name basobj3.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 EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/basctl/inc -I /home/maarten/src/libreoffice/core/basctl/sdi -I /home/maarten/src/libreoffice/core/basctl/source/inc -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/SdiTarget/basctl/sdi -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -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/basctl/source/basicide/basobj3.cxx
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | #include <vcl/errinf.hxx> |
21 | #include <vcl/svapp.hxx> |
22 | #include <vcl/weld.hxx> |
23 | #include <basic/basmgr.hxx> |
24 | #include <basic/sbmeth.hxx> |
25 | #include <unotools/moduleoptions.hxx> |
26 | |
27 | #include <iderdll.hxx> |
28 | #include "iderdll2.hxx" |
29 | #include "basdoc.hxx" |
30 | #include <iderid.hxx> |
31 | #include <strings.hrc> |
32 | |
33 | #include <baside3.hxx> |
34 | #include <basidesh.hxx> |
35 | #include <basobj.hxx> |
36 | #include <localizationmgr.hxx> |
37 | #include <dlged.hxx> |
38 | #include <com/sun/star/script/XLibraryContainerPassword.hpp> |
39 | #include <sfx2/app.hxx> |
40 | #include <sfx2/dispatch.hxx> |
41 | #include <sfx2/sfxsids.hrc> |
42 | #include <sfx2/request.hxx> |
43 | #include <sfx2/viewfrm.hxx> |
44 | #include <sal/log.hxx> |
45 | #include <osl/diagnose.h> |
46 | #include <tools/debug.hxx> |
47 | |
48 | namespace basctl |
49 | { |
50 | |
51 | using namespace comphelper; |
52 | using namespace ::com::sun::star; |
53 | using namespace ::com::sun::star::uno; |
54 | using namespace ::com::sun::star::container; |
55 | |
56 | extern "C" { |
57 | SAL_DLLPUBLIC_EXPORT long basicide_handle_basic_error( void const * pPtr ) |
58 | { |
59 | return HandleBasicError( static_cast<StarBASIC const *>(pPtr) ); |
60 | } |
61 | } |
62 | |
63 | SbMethod* CreateMacro( SbModule* pModule, const OUString& rMacroName ) |
64 | { |
65 | SfxDispatcher* pDispatcher = GetDispatcher(); |
66 | if( pDispatcher ) |
| |
67 | { |
68 | pDispatcher->Execute( SID_BASICIDE_STOREALLMODULESOURCES ); |
69 | } |
70 | |
71 | if ( pModule->FindMethod( rMacroName, SbxClassType::Method ) ) |
| 2 | | Value assigned to field 'pParent' | |
|
| 3 | | Assuming the condition is false | |
|
| |
72 | return nullptr; |
73 | |
74 | OUString aMacroName( rMacroName ); |
75 | if ( aMacroName.isEmpty() ) |
| |
76 | { |
77 | if ( !pModule->GetMethods()->Count32() ) |
78 | aMacroName = "Main" ; |
79 | else |
80 | { |
81 | bool bValid = false; |
82 | sal_Int32 nMacro = 1; |
83 | while ( !bValid ) |
84 | { |
85 | aMacroName = "Macro" + OUString::number( nMacro ); |
86 | |
87 | bValid = pModule->FindMethod( aMacroName, SbxClassType::Method ) == nullptr; |
88 | nMacro++; |
89 | } |
90 | } |
91 | } |
92 | |
93 | OUString aOUSource( pModule->GetSource32() ); |
94 | |
95 | |
96 | sal_Int32 nSourceLen = aOUSource.getLength(); |
97 | if ( nSourceLen > 2 ) |
| 6 | | Assuming 'nSourceLen' is <= 2 | |
|
| |
98 | { |
99 | const sal_Unicode* pStr = aOUSource.getStr(); |
100 | if ( pStr[ nSourceLen - 1 ] != LINE_SEP ) |
101 | aOUSource += "\n\n" ; |
102 | else if ( pStr[ nSourceLen - 2 ] != LINE_SEP ) |
103 | aOUSource += "\n" ; |
104 | else if ( pStr[ nSourceLen - 3 ] == LINE_SEP ) |
105 | aOUSource = aOUSource.copy( 0, nSourceLen-1 ); |
106 | } |
107 | |
108 | OUString aSubStr = "Sub " + aMacroName + "\n\nEnd Sub"; |
109 | |
110 | aOUSource += aSubStr; |
111 | |
112 | |
113 | StarBASIC* pBasic = dynamic_cast<StarBASIC*>(pModule->GetParent()); |
| 8 | | 'pBasic' initialized here | |
|
114 | BasicManager* pBasMgr = pBasic ? FindBasicManager(pBasic) : nullptr; |
| 9 | | Assuming 'pBasic' is null | |
|
| |
115 | SAL_WARN_IF(!pBasMgr, "basctl.basicide", "No BasicManager found!"); |
| |
| 12 | | 'Default' branch taken. Execution continues on line 115 | |
|
| 13 | | Loop condition is false. Exiting loop | |
|
116 | ScriptDocument aDocument = pBasMgr |
| |
117 | ? ScriptDocument::getDocumentForBasicManager(pBasMgr) |
118 | : ScriptDocument(ScriptDocument::NoDocument); |
119 | |
120 | if (aDocument.isValid()) |
| 15 | | Assuming the condition is true | |
|
| |
121 | { |
122 | const OUString& aLibName = pBasic->GetName(); |
| 17 | | Called C++ object pointer is null |
|
123 | const OUString& aModName = pModule->GetName(); |
124 | OSL_VERIFY( aDocument.updateModule( aLibName, aModName, aOUSource ) ); |
125 | } |
126 | |
127 | SbMethod* pMethod = pModule->FindMethod( aMacroName, SbxClassType::Method ); |
128 | |
129 | if( pDispatcher ) |
130 | { |
131 | pDispatcher->Execute( SID_BASICIDE_UPDATEALLMODULESOURCES ); |
132 | } |
133 | |
134 | if (aDocument.isAlive()) |
135 | MarkDocumentModified(aDocument); |
136 | |
137 | return pMethod; |
138 | } |
139 | |
140 | bool RenameDialog ( |
141 | weld::Widget* pErrorParent, |
142 | ScriptDocument const& rDocument, |
143 | OUString const& rLibName, |
144 | OUString const& rOldName, |
145 | OUString const& rNewName |
146 | ) |
147 | { |
148 | if ( !rDocument.hasDialog( rLibName, rOldName ) ) |
149 | { |
150 | OSL_FAIL( "basctl::RenameDialog: old module name is invalid!" ); |
151 | return false; |
152 | } |
153 | |
154 | if ( rDocument.hasDialog( rLibName, rNewName ) ) |
155 | { |
156 | std::unique_ptr<weld::MessageDialog> xError(Application::CreateMessageDialog(pErrorParent, |
157 | VclMessageType::Warning, VclButtonsType::Ok, IDEResId(RID_STR_SBXNAMEALLREADYUSED2))); |
158 | xError->run(); |
159 | return false; |
160 | } |
161 | |
162 | |
163 | if ( rNewName.isEmpty() ) |
164 | { |
165 | std::unique_ptr<weld::MessageDialog> xError(Application::CreateMessageDialog(pErrorParent, |
166 | VclMessageType::Warning, VclButtonsType::Ok, IDEResId(RID_STR_BADSBXNAME))); |
167 | xError->run(); |
168 | return false; |
169 | } |
170 | |
171 | Shell* pShell = GetShell(); |
172 | VclPtr<DialogWindow> pWin = pShell ? pShell->FindDlgWin(rDocument, rLibName, rOldName) : nullptr; |
173 | Reference< XNameContainer > xExistingDialog; |
174 | if ( pWin ) |
175 | xExistingDialog = pWin->GetEditor().GetDialog(); |
176 | |
177 | if ( xExistingDialog.is() ) |
178 | LocalizationMgr::renameStringResourceIDs( rDocument, rLibName, rNewName, xExistingDialog ); |
179 | |
180 | if ( !rDocument.renameDialog( rLibName, rOldName, rNewName, xExistingDialog ) ) |
181 | return false; |
182 | |
183 | if (pWin && pShell) |
184 | { |
185 | |
186 | pWin->SetName( rNewName ); |
187 | |
188 | |
189 | pWin->UpdateBrowser(); |
190 | |
191 | |
192 | sal_uInt16 nId = pShell->GetWindowId( pWin ); |
193 | DBG_ASSERT( nId, "No entry in Tabbar!" ); |
194 | if ( nId ) |
195 | { |
196 | TabBar& rTabBar = pShell->GetTabBar(); |
197 | rTabBar.SetPageText( nId, rNewName ); |
198 | rTabBar.Sort(); |
199 | rTabBar.MakeVisible( rTabBar.GetCurPageId() ); |
200 | } |
201 | } |
202 | return true; |
203 | } |
204 | |
205 | bool RemoveDialog( const ScriptDocument& rDocument, const OUString& rLibName, const OUString& rDlgName ) |
206 | { |
207 | if (Shell* pShell = GetShell()) |
208 | { |
209 | if (VclPtr<DialogWindow> pDlgWin = pShell->FindDlgWin(rDocument, rLibName, rDlgName)) |
210 | { |
211 | Reference< container::XNameContainer > xDialogModel = pDlgWin->GetDialog(); |
212 | LocalizationMgr::removeResourceForDialog( rDocument, rLibName, rDlgName, xDialogModel ); |
213 | } |
214 | } |
215 | |
216 | return rDocument.removeDialog( rLibName, rDlgName ); |
217 | } |
218 | |
219 | StarBASIC* FindBasic( const SbxVariable* pVar ) |
220 | { |
221 | SbxVariable const* pSbx = pVar; |
222 | while (pSbx && !dynamic_cast<StarBASIC const*>(pSbx)) |
223 | pSbx = pSbx->GetParent(); |
224 | return const_cast<StarBASIC*>(static_cast<const StarBASIC*>(pSbx)); |
225 | } |
226 | |
227 | BasicManager* FindBasicManager( StarBASIC const * pLib ) |
228 | { |
229 | ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::AllWithApplication ) ); |
230 | for (auto const& doc : aDocuments) |
231 | { |
232 | BasicManager* pBasicMgr = doc.getBasicManager(); |
233 | OSL_ENSURE( pBasicMgr, "basctl::FindBasicManager: no basic manager for the document!" ); |
234 | if ( !pBasicMgr ) |
235 | continue; |
236 | |
237 | Sequence< OUString > aLibNames( doc.getLibraryNames() ); |
238 | sal_Int32 nLibCount = aLibNames.getLength(); |
239 | const OUString* pLibNames = aLibNames.getConstArray(); |
240 | |
241 | for ( sal_Int32 i = 0 ; i < nLibCount ; i++ ) |
242 | { |
243 | StarBASIC* pL = pBasicMgr->GetLib( pLibNames[ i ] ); |
244 | if ( pL == pLib ) |
245 | return pBasicMgr; |
246 | } |
247 | } |
248 | return nullptr; |
249 | } |
250 | |
251 | void MarkDocumentModified( const ScriptDocument& rDocument ) |
252 | { |
253 | Shell* pShell = GetShell(); |
254 | |
255 | |
256 | if ( rDocument.isApplication() ) |
257 | { |
258 | if (pShell) |
259 | pShell->SetAppBasicModified(true); |
260 | } |
261 | else |
262 | { |
263 | rDocument.setDocumentModified(); |
264 | } |
265 | |
266 | |
267 | if (pShell) |
268 | pShell->UpdateObjectCatalog(); |
269 | |
270 | if (SfxBindings* pBindings = GetBindingsPtr()) |
271 | { |
272 | pBindings->Invalidate( SID_SIGNATURE ); |
273 | pBindings->Invalidate( SID_SAVEDOC ); |
274 | pBindings->Update( SID_SAVEDOC ); |
275 | } |
276 | } |
277 | |
278 | void RunMethod( SbMethod const * pMethod ) |
279 | { |
280 | SbxValues aRes; |
281 | aRes.eType = SbxVOID; |
282 | pMethod->Get( aRes ); |
283 | } |
284 | |
285 | void StopBasic() |
286 | { |
287 | StarBASIC::Stop(); |
288 | if (Shell* pShell = GetShell()) |
289 | { |
290 | Shell::WindowTable& rWindows = pShell->GetWindowTable(); |
291 | for (auto const& window : rWindows) |
292 | { |
293 | BaseWindow* pWin = window.second; |
294 | |
295 | |
296 | pWin->BasicStopped(); |
297 | } |
298 | } |
299 | BasicStopped(); |
300 | } |
301 | |
302 | void BasicStopped( |
303 | bool* pbAppWindowDisabled, |
304 | bool* pbDispatcherLocked, |
305 | sal_uInt16* pnWaitCount, |
306 | SfxUInt16Item** ppSWActionCount, SfxUInt16Item** ppSWLockViewCount |
307 | ) |
308 | { |
309 | |
310 | |
311 | if ( pbAppWindowDisabled ) |
312 | *pbAppWindowDisabled = false; |
313 | if ( pbDispatcherLocked ) |
314 | *pbDispatcherLocked = false; |
315 | if ( pnWaitCount ) |
316 | *pnWaitCount = 0; |
317 | if ( ppSWActionCount ) |
318 | *ppSWActionCount = nullptr; |
319 | if ( ppSWLockViewCount ) |
320 | *ppSWLockViewCount = nullptr; |
321 | |
322 | |
323 | if (Shell* pShell = GetShell()) |
324 | { |
325 | sal_uInt16 nWait = 0; |
326 | while ( pShell->GetViewFrame()->GetWindow().IsWait() ) |
327 | { |
328 | pShell->GetViewFrame()->GetWindow().LeaveWait(); |
329 | nWait++; |
330 | } |
331 | if ( pnWaitCount ) |
332 | *pnWaitCount = nWait; |
333 | } |
334 | |
335 | vcl::Window* pDefParent = Application::GetDefDialogParent(); |
336 | if ( pDefParent && !pDefParent->IsEnabled() ) |
337 | { |
338 | pDefParent->Enable(); |
339 | if ( pbAppWindowDisabled ) |
340 | *pbAppWindowDisabled = true; |
341 | } |
342 | |
343 | } |
344 | |
345 | void InvalidateDebuggerSlots() |
346 | { |
347 | SfxBindings* pBindings = GetBindingsPtr(); |
348 | if (!pBindings) |
349 | return; |
350 | |
351 | pBindings->Invalidate( SID_BASICSTOP ); |
352 | pBindings->Update( SID_BASICSTOP ); |
353 | pBindings->Invalidate( SID_BASICRUN ); |
354 | pBindings->Update( SID_BASICRUN ); |
355 | pBindings->Invalidate( SID_BASICCOMPILE ); |
356 | pBindings->Update( SID_BASICCOMPILE ); |
357 | pBindings->Invalidate( SID_BASICSTEPOVER ); |
358 | pBindings->Update( SID_BASICSTEPOVER ); |
359 | pBindings->Invalidate( SID_BASICSTEPINTO ); |
360 | pBindings->Update( SID_BASICSTEPINTO ); |
361 | pBindings->Invalidate( SID_BASICSTEPOUT ); |
362 | pBindings->Update( SID_BASICSTEPOUT ); |
363 | pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT ); |
364 | pBindings->Update( SID_BASICIDE_TOGGLEBRKPNT ); |
365 | pBindings->Invalidate( SID_BASICIDE_STAT_POS ); |
366 | pBindings->Update( SID_BASICIDE_STAT_POS ); |
367 | pBindings->Invalidate( SID_BASICIDE_STAT_TITLE ); |
368 | pBindings->Update( SID_BASICIDE_STAT_TITLE ); |
369 | } |
370 | |
371 | long HandleBasicError( StarBASIC const * pBasic ) |
372 | { |
373 | EnsureIde(); |
374 | BasicStopped(); |
375 | |
376 | |
377 | if (GetExtraData()->ChoosingMacro()) |
378 | return 1; |
379 | if (GetExtraData()->ShellInCriticalSection()) |
380 | return 2; |
381 | |
382 | long nRet = 0; |
383 | Shell* pShell = nullptr; |
384 | if ( SvtModuleOptions::IsBasicIDE() ) |
385 | { |
386 | BasicManager* pBasMgr = FindBasicManager( pBasic ); |
387 | if ( pBasMgr ) |
388 | { |
389 | bool bProtected = false; |
390 | ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) ); |
391 | OSL_ENSURE( aDocument.isValid(), "basctl::HandleBasicError: no document for the given BasicManager!" ); |
392 | if ( aDocument.isValid() ) |
393 | { |
394 | const OUString& aOULibName( pBasic->GetName() ); |
395 | Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ) ); |
396 | if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) ) |
397 | { |
398 | Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY ); |
399 | if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) ) |
400 | { |
401 | bProtected = true; |
402 | } |
403 | } |
404 | } |
405 | |
406 | if ( !bProtected ) |
407 | { |
408 | pShell = GetShell(); |
409 | if ( !pShell ) |
410 | { |
411 | SfxAllItemSet aArgs( SfxGetpApp()->GetPool() ); |
412 | SfxRequest aRequest( SID_BASICIDE_APPEAR, SfxCallMode::SYNCHRON, aArgs ); |
413 | SfxGetpApp()->ExecuteSlot( aRequest ); |
414 | pShell = GetShell(); |
415 | } |
416 | } |
417 | } |
418 | } |
419 | |
420 | if ( pShell ) |
421 | nRet = long(pShell->CallBasicErrorHdl( pBasic )); |
422 | else |
423 | ErrorHandler::HandleError( StarBASIC::GetErrorCode() ); |
424 | |
425 | return nRet; |
426 | } |
427 | |
428 | SfxBindings* GetBindingsPtr() |
429 | { |
430 | SfxBindings* pBindings = nullptr; |
431 | |
432 | SfxViewFrame* pFrame = nullptr; |
433 | if (Shell* pShell = GetShell()) |
434 | { |
435 | pFrame = pShell->GetViewFrame(); |
436 | } |
437 | else |
438 | { |
439 | SfxViewFrame* pView = SfxViewFrame::GetFirst(); |
440 | while ( pView ) |
441 | { |
442 | if (dynamic_cast<DocShell*>(pView->GetObjectShell())) |
443 | { |
444 | pFrame = pView; |
445 | break; |
446 | } |
447 | pView = SfxViewFrame::GetNext( *pView ); |
448 | } |
449 | } |
450 | if ( pFrame != nullptr ) |
451 | pBindings = &pFrame->GetBindings(); |
452 | |
453 | return pBindings; |
454 | } |
455 | |
456 | SfxDispatcher* GetDispatcher () |
457 | { |
458 | if (Shell* pShell = GetShell()) |
459 | if (SfxViewFrame* pViewFrame = pShell->GetViewFrame()) |
460 | if (SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher()) |
461 | return pDispatcher; |
462 | return nullptr; |
463 | } |
464 | } |
465 | |
466 | |