Bug Summary

File:home/maarten/src/libreoffice/core/sw/source/uibase/shells/txtnum.cxx
Warning:line 179, column 9
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 txtnum.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/uibase/shells/txtnum.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 <sfx2/request.hxx>
21#include <svl/eitem.hxx>
22#include <svl/stritem.hxx>
23#include <editeng/numitem.hxx>
24#include <editeng/brushitem.hxx>
25#include <numrule.hxx>
26
27#include <cmdid.h>
28#include <wrtsh.hxx>
29#include <view.hxx>
30#include <viewopt.hxx>
31#include <wdocsh.hxx>
32#include <poolfmt.hxx>
33#include <textsh.hxx>
34#include <swabstdlg.hxx>
35#include <SwStyleNameMapper.hxx>
36#include <sfx2/tabdlg.hxx>
37#include <svx/nbdtmg.hxx>
38#include <svx/nbdtmgfact.hxx>
39#include <sfx2/viewfrm.hxx>
40#include <sfx2/bindings.hxx>
41#include <memory>
42
43void SwTextShell::ExecEnterNum(SfxRequest &rReq)
44{
45 //Because the record before any shell exchange.
46 switch(rReq.GetSlot())
1
Control jumps to 'case 10156:' at line 108
47 {
48 case FN_NUM_NUMBERING_ON((20000 + 100) + 44):
49 {
50 GetShell().StartAllAction();
51 const SfxBoolItem* pItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_1((20000 + 1100)+60));
52 bool bMode = !GetShell().SelectionHasNumber(); // #i29560#
53 if ( pItem )
54 bMode = pItem->GetValue();
55 else
56 rReq.AppendItem( SfxBoolItem( FN_PARAM_1((20000 + 1100)+60), bMode ) );
57
58 if ( bMode != (GetShell().SelectionHasNumber()) ) // #i29560#
59 {
60 rReq.Done();
61 if( bMode )
62 GetShell().NumOn();
63 else
64 GetShell().NumOrBulletOff(); // #i29560#
65 }
66 bool bNewResult = GetShell().SelectionHasNumber();
67 if (bNewResult!=bMode) {
68 SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
69 SfxBoolItem aItem(FN_NUM_NUMBERING_ON((20000 + 100) + 44),!bNewResult);
70 rBindings.SetState(aItem);
71 SfxBoolItem aNewItem(FN_NUM_NUMBERING_ON((20000 + 100) + 44),bNewResult);
72 rBindings.SetState(aNewItem);
73 }
74 GetShell().EndAllAction();
75 }
76 break;
77 case FN_NUM_BULLET_ON((20000 + 100) + 38):
78 {
79 GetShell().StartAllAction();
80 const SfxBoolItem* pItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_1((20000 + 1100)+60));
81 bool bMode = !GetShell().SelectionHasBullet(); // #i29560#
82 if ( pItem )
83 bMode = pItem->GetValue();
84 else
85 rReq.AppendItem( SfxBoolItem( FN_PARAM_1((20000 + 1100)+60), bMode ) );
86
87 if ( bMode != (GetShell().SelectionHasBullet()) ) // #i29560#
88 {
89 rReq.Done();
90 if( bMode )
91 GetShell().BulletOn();
92 else
93 GetShell().NumOrBulletOff(); // #i29560#
94 }
95 bool bNewResult = GetShell().SelectionHasBullet();
96 if (bNewResult!=bMode) {
97 SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
98 SfxBoolItem aItem(FN_NUM_BULLET_ON((20000 + 100) + 38),!bNewResult);
99 rBindings.SetState(aItem);
100 SfxBoolItem aNewItem(FN_NUM_BULLET_ON((20000 + 100) + 38),bNewResult);
101 rBindings.SetState(aNewItem);
102 }
103 GetShell().EndAllAction();
104 }
105 break;
106
107 case FN_NUMBER_BULLETS((20000 + 100) + 21):
108 case SID_OUTLINE_BULLET( 10000 + 156 ):
109 {
110 SfxItemSet aSet( GetPool(),
111 svl::Items<SID_HTML_MODE(10000 + 414), SID_HTML_MODE(10000 + 414),
112 SID_ATTR_NUMBERING_RULE( 10000 + 855 ), SID_PARAM_CUR_NUM_LEVEL( 10000 + 859 )>{} );
113 SwDocShell* pDocSh = GetView().GetDocShell();
2
'pDocSh' initialized here
114 const bool bHtml = dynamic_cast<SwWebDocShell*>( pDocSh ) != nullptr;
3
Assuming pointer value is null
115 const SwNumRule* pNumRuleAtCurrentSelection = GetShell().GetNumRuleAtCurrentSelection();
116 if ( pNumRuleAtCurrentSelection != nullptr )
4
Assuming the condition is false
5
Taking false branch
117 {
118 SvxNumRule aRule = pNumRuleAtCurrentSelection->MakeSvxNumRule();
119
120 //convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
121 for ( sal_uInt16 i = 0; i < aRule.GetLevelCount(); i++ )
122 {
123 SvxNumberFormat aFormat( aRule.GetLevel( i ) );
124 if ( SVX_NUM_BITMAP == aFormat.GetNumberingType() )
125 {
126 const SvxBrushItem* pBrush = aFormat.GetBrush();
127 if(pBrush && !pBrush->GetGraphicLink().isEmpty())
128 aFormat.SetNumberingType(SvxNumType(SVX_NUM_BITMAP|LINK_TOKEN0x80));
129 aRule.SetLevel(i, aFormat, aRule.Get(i) != nullptr);
130 }
131 }
132 if(bHtml)
133 aRule.SetFeatureFlag(SvxNumRuleFlags::ENABLE_EMBEDDED_BMP, false);
134
135 aSet.Put(SvxNumBulletItem(aRule));
136 OSL_ENSURE( GetShell().GetNumLevel() < MAXLEVEL,do { if (true && (!(GetShell().GetNumLevel() < MAXLEVEL
))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/txtnum.cxx"
":" "137" ": "), "%s", "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect."
); } } while (false)
137 "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect." )do { if (true && (!(GetShell().GetNumLevel() < MAXLEVEL
))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/txtnum.cxx"
":" "137" ": "), "%s", "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect."
); } } while (false)
;
138 sal_uInt16 nLevel = GetShell().GetNumLevel();
139 if( nLevel < MAXLEVEL )
140 {
141 nLevel = 1 << nLevel;
142 aSet.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL( 10000 + 859 ), nLevel ) );
143 }
144 }
145 else
146 {
147 SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
148 // #i89178#
149 numfunc::GetDefaultPositionAndSpaceMode() );
150 SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
151 const bool bRightToLeft = GetShell().IsInRightToLeftText();
152
153 if ( bHtml
5.1
'bHtml' is false
|| bRightToLeft )
6
Assuming 'bRightToLeft' is false
7
Taking false branch
154 {
155 for ( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
156 {
157 SvxNumberFormat aFormat( aSvxRule.GetLevel( n ) );
158 if ( n && bHtml )
159 {
160 // 1/2" for HTML
161 aFormat.SetAbsLSpace(n * 720);
162 }
163 // #i38904# Default alignment for
164 // numbering/bullet should be rtl in rtl paragraph:
165 if ( bRightToLeft )
166 {
167 aFormat.SetNumAdjust( SvxAdjust::Right );
168 }
169 aSvxRule.SetLevel( n, aFormat, false );
170 }
171 aSvxRule.SetFeatureFlag(SvxNumRuleFlags::ENABLE_EMBEDDED_BMP, false);
172 }
173 aSet.Put( SvxNumBulletItem( aSvxRule ) );
174 }
175
176 aSet.Put( SfxBoolItem( SID_PARAM_NUM_PRESET( 10000 + 856 ),false ));
177
178 // Before the dialogue of the HTML mode will be dropped at the Docshell.
179 pDocSh->PutItem(SfxUInt16Item(SID_HTML_MODE(10000 + 414), ::GetHtmlMode(pDocSh)));
8
Called C++ object pointer is null
180
181 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
182 weld::Window *pParent = rReq.GetFrameWeld();
183 VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSvxNumBulletTabDialog(pParent, &aSet, GetShell()));
184 const SfxStringItem* pPageItem = rReq.GetArg<SfxStringItem>(FN_PARAM_1((20000 + 1100)+60));
185 if ( pPageItem )
186 pDlg->SetCurPageId( OUStringToOString( pPageItem->GetValue(), RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)) ) );
187
188 auto pRequest = std::make_shared<SfxRequest>(rReq);
189 rReq.Ignore(); // the 'old' request is not relevant any more
190
191 pDlg->StartExecuteAsync([aSet, pDlg, pNumRuleAtCurrentSelection, pRequest, this](sal_Int32 nResult){
192 if (RET_OK == nResult)
193 {
194 const SfxPoolItem* pItem;
195 if (SfxItemState::SET == pDlg->GetOutputItemSet()->GetItemState(SID_ATTR_NUMBERING_RULE( 10000 + 855 ), false, &pItem))
196 {
197 pRequest->AppendItem(*pItem);
198 pRequest->Done();
199 SvxNumRule* pSetRule = static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule();
200 pSetRule->UnLinkGraphics();
201 SwNumRule aSetRule(pNumRuleAtCurrentSelection != nullptr
202 ? pNumRuleAtCurrentSelection->GetName()
203 : GetShell().GetUniqueNumRuleName(),
204 numfunc::GetDefaultPositionAndSpaceMode());
205 aSetRule.SetSvxRule(*pSetRule, GetShell().GetDoc());
206 aSetRule.SetAutoRule(true);
207 // No start of new list, if an existing list style is edited.
208 // Otherwise start a new list.
209 const bool bCreateList = (pNumRuleAtCurrentSelection == nullptr);
210 GetShell().SetCurNumRule(aSetRule, bCreateList);
211 }
212 // If the Dialog was leaved with OK but nothing was chosen then the
213 // numbering must be at least activated, if it is not already.
214 else if (pNumRuleAtCurrentSelection == nullptr
215 && SfxItemState::SET == aSet.GetItemState(SID_ATTR_NUMBERING_RULE( 10000 + 855 ), false, &pItem))
216 {
217 pRequest->AppendItem(*pItem);
218 pRequest->Done();
219 SvxNumRule* pSetRule = static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule();
220 SwNumRule aSetRule(
221 GetShell().GetUniqueNumRuleName(),
222 numfunc::GetDefaultPositionAndSpaceMode());
223 aSetRule.SetSvxRule(*pSetRule, GetShell().GetDoc());
224 aSetRule.SetAutoRule(true);
225 // start new list
226 GetShell().SetCurNumRule(aSetRule, true);
227 }
228 }
229 else if (RET_USER100 == nResult)
230 GetShell().DelNumRules();
231 pDlg->disposeOnce();
232 });
233 }
234 break;
235
236 default:
237 OSL_FAIL("wrong dispatcher")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/txtnum.cxx"
":" "237" ": "), "%s", "wrong dispatcher"); } } while (false
)
;
238 return;
239 }
240}
241
242
243void SwTextShell::ExecSetNumber(SfxRequest const &rReq)
244{
245 const sal_uInt16 nSlot = rReq.GetSlot();
246 switch ( nSlot )
247 {
248 case FN_SVX_SET_NUMBER( 10000 + 1136 ):
249 case FN_SVX_SET_BULLET( 10000 + 1137 ):
250 case FN_SVX_SET_OUTLINE( 10000 + 1138 ):
251 {
252 const SfxUInt16Item* pItem = rReq.GetArg<SfxUInt16Item>(nSlot);
253 if ( pItem != nullptr )
254 {
255 const sal_uInt16 nChosenItemIdx = pItem->GetValue();
256 svx::sidebar::NBOType nNBOType = svx::sidebar::NBOType::Bullets;
257 if ( nSlot == FN_SVX_SET_NUMBER( 10000 + 1136 ) )
258 nNBOType = svx::sidebar::NBOType::Numbering;
259 else if ( nSlot == FN_SVX_SET_OUTLINE( 10000 + 1138 ) )
260 nNBOType = svx::sidebar::NBOType::Outline;
261
262 svx::sidebar::NBOTypeMgrBase* pNBOTypeMgr = svx::sidebar::NBOutlineTypeMgrFact::CreateInstance( nNBOType );
263
264 if ( pNBOTypeMgr != nullptr )
265 {
266 const SwNumRule* pNumRuleAtCurrentSelection = GetShell().GetNumRuleAtCurrentSelection();
267 sal_uInt16 nActNumLvl = USHRT_MAX(32767 *2 +1);
268 if ( pNumRuleAtCurrentSelection != nullptr )
269 {
270 const sal_uInt16 nLevel = GetShell().GetNumLevel();
271 if ( nLevel < MAXLEVEL )
272 {
273 nActNumLvl = 1 << nLevel;
274 }
275 }
276 SwNumRule aNewNumRule(
277 pNumRuleAtCurrentSelection != nullptr ? pNumRuleAtCurrentSelection->GetName() : GetShell().GetUniqueNumRuleName(),
278 numfunc::GetDefaultPositionAndSpaceMode() );
279 SvxNumRule aNewSvxNumRule = pNumRuleAtCurrentSelection != nullptr
280 ? pNumRuleAtCurrentSelection->MakeSvxNumRule()
281 : aNewNumRule.MakeSvxNumRule();
282
283 OUString aNumCharFormat, aBulletCharFormat;
284 SwStyleNameMapper::FillUIName( RES_POOLCHR_NUM_LEVEL, aNumCharFormat );
285 SwStyleNameMapper::FillUIName( RES_POOLCHR_BULLET_LEVEL, aBulletCharFormat );
286
287 SfxAllItemSet aSet( GetPool() );
288 aSet.Put( SfxStringItem( SID_NUM_CHAR_FMT( 10000 + 1025 ), aNumCharFormat ) );
289 aSet.Put( SfxStringItem( SID_BULLET_CHAR_FMT( 10000 + 1026 ), aBulletCharFormat ) );
290 aSet.Put( SvxNumBulletItem( aNewSvxNumRule, SID_ATTR_NUMBERING_RULE( 10000 + 855 ) ) );
291
292 pNBOTypeMgr->SetItems( &aSet );
293 pNBOTypeMgr->ApplyNumRule( aNewSvxNumRule, nChosenItemIdx - 1, nActNumLvl );
294
295 aNewNumRule.SetSvxRule( aNewSvxNumRule, GetShell().GetDoc() );
296 aNewNumRule.SetAutoRule( true );
297 const bool bCreateNewList = ( pNumRuleAtCurrentSelection == nullptr );
298 GetShell().SetCurNumRule( aNewNumRule, bCreateNewList );
299 }
300 }
301 }
302 break;
303
304 default:
305 OSL_ENSURE(false, "wrong Dispatcher")do { if (true && (!(false))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/txtnum.cxx"
":" "305" ": "), "%s", "wrong Dispatcher"); } } while (false
)
;
306 return;
307 }
308}
309
310/* vim:set shiftwidth=4 softtabstop=4 expandtab: */