Bug Summary

File:home/maarten/src/libreoffice/core/sc/source/ui/miscdlgs/tabopdlg.cxx
Warning:line 164, column 23
Value stored to 'pEd' during its initialization is never read

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 tabopdlg.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 SC_DLLIMPLEMENTATION -D SC_INFO_OSVERSION="LINUX" -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/liborcus/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/mdds/include -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/clew/source/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/sc/source/core/inc -I /home/maarten/src/libreoffice/core/sc/source/filter/inc -I /home/maarten/src/libreoffice/core/sc/source/ui/inc -I /home/maarten/src/libreoffice/core/sc/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/sc/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/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/sc/source/ui/miscdlgs/tabopdlg.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/dispatch.hxx>
21#include <vcl/svapp.hxx>
22#include <vcl/weld.hxx>
23
24#include <uiitems.hxx>
25#include <document.hxx>
26#include <scresid.hxx>
27#include <sc.hrc>
28#include <strings.hrc>
29#include <reffact.hxx>
30
31#include <tabopdlg.hxx>
32
33
34ScTabOpDlg::ScTabOpDlg(SfxBindings* pB, SfxChildWindow* pCW, weld::Window* pParent,
35 ScDocument* pDocument,
36 const ScRefAddress& rCursorPos )
37 : ScAnyRefDlgController(pB, pCW, pParent, "modules/scalc/ui/multipleoperationsdialog.ui",
38 "MultipleOperationsDialog")
39 , theFormulaCell(rCursorPos)
40 , pDoc(pDocument)
41 , nCurTab(theFormulaCell.Tab())
42 , bDlgLostFocus(false)
43 , errMsgNoFormula(ScResId(STR_NOFORMULASPECIFIEDreinterpret_cast<char const *>("STR_NOFORMULASPECIFIED"
"\004" u8"No formula specified.")
))
44 , errMsgNoColRow(ScResId(STR_NOCOLROWreinterpret_cast<char const *>("STR_NOCOLROW" "\004" u8"Neither row or column specified."
)
))
45 , errMsgWrongFormula(ScResId(STR_WRONGFORMULAreinterpret_cast<char const *>("STR_WRONGFORMULA" "\004"
u8"Undefined name or range.")
))
46 , errMsgWrongRowCol(ScResId(STR_WRONGROWCOLreinterpret_cast<char const *>("STR_WRONGROWCOL" "\004"
u8"Undefined name or wrong cell reference.")
))
47 , errMsgNoColFormula(ScResId(STR_NOCOLFORMULAreinterpret_cast<char const *>("STR_NOCOLFORMULA" "\004"
u8"Formulas don't form a column.")
))
48 , errMsgNoRowFormula(ScResId(STR_NOROWFORMULAreinterpret_cast<char const *>("STR_NOROWFORMULA" "\004"
u8"Formulas don't form a row.")
))
49 , m_pEdActive(nullptr)
50 , m_xFtFormulaRange(m_xBuilder->weld_label("formulasft"))
51 , m_xEdFormulaRange(new formula::RefEdit(m_xBuilder->weld_entry("formulas")))
52 , m_xRBFormulaRange(new formula::RefButton(m_xBuilder->weld_button("formulasref")))
53 , m_xFtRowCell(m_xBuilder->weld_label("rowft"))
54 , m_xEdRowCell(new formula::RefEdit(m_xBuilder->weld_entry("row")))
55 , m_xRBRowCell(new formula::RefButton(m_xBuilder->weld_button("rowref")))
56 , m_xFtColCell(m_xBuilder->weld_label("colft"))
57 , m_xEdColCell(new formula::RefEdit(m_xBuilder->weld_entry("col")))
58 , m_xRBColCell(new formula::RefButton(m_xBuilder->weld_button("colref")))
59 , m_xBtnOk(m_xBuilder->weld_button("ok"))
60 , m_xBtnCancel(m_xBuilder->weld_button("cancel"))
61{
62 m_xEdFormulaRange->SetReferences(this, m_xFtFormulaRange.get());
63 m_xRBFormulaRange->SetReferences(this, m_xEdFormulaRange.get());
64
65 m_xEdRowCell->SetReferences(this, m_xFtRowCell.get());
66 m_xRBRowCell->SetReferences(this, m_xEdRowCell.get());
67
68 m_xEdColCell->SetReferences(this, m_xFtColCell.get());
69 m_xRBColCell->SetReferences(this, m_xEdColCell.get());
70
71 Init();
72}
73
74ScTabOpDlg::~ScTabOpDlg()
75{
76}
77
78void ScTabOpDlg::Init()
79{
80 m_xBtnOk->connect_clicked( LINK( this, ScTabOpDlg, BtnHdl )::tools::detail::makeLink( ::tools::detail::castTo<ScTabOpDlg
*>(this), &ScTabOpDlg::LinkStubBtnHdl)
);
81 m_xBtnCancel->connect_clicked( LINK( this, ScTabOpDlg, BtnHdl )::tools::detail::makeLink( ::tools::detail::castTo<ScTabOpDlg
*>(this), &ScTabOpDlg::LinkStubBtnHdl)
);
82
83 Link<formula::RefEdit&,void> aEditLink = LINK( this, ScTabOpDlg, GetEditFocusHdl )::tools::detail::makeLink( ::tools::detail::castTo<ScTabOpDlg
*>(this), &ScTabOpDlg::LinkStubGetEditFocusHdl)
;
84 m_xEdFormulaRange->SetGetFocusHdl( aEditLink );
85 m_xEdRowCell->SetGetFocusHdl( aEditLink );
86 m_xEdColCell->SetGetFocusHdl( aEditLink );
87
88 Link<formula::RefButton&,void> aButtonLink = LINK( this, ScTabOpDlg, GetButtonFocusHdl )::tools::detail::makeLink( ::tools::detail::castTo<ScTabOpDlg
*>(this), &ScTabOpDlg::LinkStubGetButtonFocusHdl)
;
89 m_xRBFormulaRange->SetGetFocusHdl( aButtonLink );
90 m_xRBRowCell->SetGetFocusHdl( aButtonLink );
91 m_xRBColCell->SetGetFocusHdl( aButtonLink );
92
93 aEditLink = LINK( this, ScTabOpDlg, LoseEditFocusHdl )::tools::detail::makeLink( ::tools::detail::castTo<ScTabOpDlg
*>(this), &ScTabOpDlg::LinkStubLoseEditFocusHdl)
;
94 m_xEdFormulaRange->SetLoseFocusHdl( aEditLink );
95 m_xEdRowCell->SetLoseFocusHdl( aEditLink );
96 m_xEdColCell->SetLoseFocusHdl( aEditLink );
97
98 aButtonLink = LINK( this, ScTabOpDlg, LoseButtonFocusHdl )::tools::detail::makeLink( ::tools::detail::castTo<ScTabOpDlg
*>(this), &ScTabOpDlg::LinkStubLoseButtonFocusHdl)
;
99 m_xRBFormulaRange->SetLoseFocusHdl( aButtonLink );
100 m_xRBRowCell->SetLoseFocusHdl( aButtonLink );
101 m_xRBColCell->SetLoseFocusHdl( aButtonLink );
102
103 m_xEdFormulaRange->GrabFocus();
104 m_pEdActive = m_xEdFormulaRange.get();
105}
106
107void ScTabOpDlg::Close()
108{
109 DoClose( ScTabOpDlgWrapper::GetChildWindowId() );
110}
111
112void ScTabOpDlg::SetActive()
113{
114 if ( bDlgLostFocus )
115 {
116 bDlgLostFocus = false;
117 if (m_pEdActive)
118 m_pEdActive->GrabFocus();
119 }
120 else
121 m_xDialog->grab_focus();
122
123 RefInputDone();
124}
125
126void ScTabOpDlg::SetReference( const ScRange& rRef, ScDocument& rDocP )
127{
128 if (!m_pEdActive)
129 return;
130
131 ScAddress::Details aDetails(rDocP.GetAddressConvention(), 0, 0);
132
133 if ( rRef.aStart != rRef.aEnd )
134 RefInputStart(m_pEdActive);
135
136 OUString aStr;
137 ScRefFlags nFmt = ( rRef.aStart.Tab() == nCurTab )
138 ? ScRefFlags::RANGE_ABS
139 : ScRefFlags::RANGE_ABS_3D;
140
141 if (m_pEdActive == m_xEdFormulaRange.get())
142 {
143 theFormulaCell.Set( rRef.aStart, false, false, false);
144 theFormulaEnd.Set( rRef.aEnd, false, false, false);
145 aStr = rRef.Format(rDocP, nFmt, aDetails);
146 }
147 else if (m_pEdActive == m_xEdRowCell.get())
148 {
149 theRowCell.Set( rRef.aStart, false, false, false);
150 aStr = rRef.aStart.Format(nFmt, &rDocP, aDetails);
151 }
152 else if (m_pEdActive == m_xEdColCell.get())
153 {
154 theColCell.Set( rRef.aStart, false, false, false);
155 aStr = rRef.aStart.Format(nFmt, &rDocP, aDetails);
156 }
157
158 m_pEdActive->SetRefString( aStr );
159}
160
161void ScTabOpDlg::RaiseError( ScTabOpErr eError )
162{
163 const OUString* pMsg = &errMsgNoFormula;
164 formula::RefEdit* pEd = m_xEdFormulaRange.get();
Value stored to 'pEd' during its initialization is never read
165
166 switch ( eError )
167 {
168 case TABOPERR_NOFORMULA:
169 pMsg = &errMsgNoFormula;
170 pEd = m_xEdFormulaRange.get();
171 break;
172
173 case TABOPERR_NOCOLROW:
174 pMsg = &errMsgNoColRow;
175 pEd = m_xEdRowCell.get();
176 break;
177
178 case TABOPERR_WRONGFORMULA:
179 pMsg = &errMsgWrongFormula;
180 pEd = m_xEdFormulaRange.get();
181 break;
182
183 case TABOPERR_WRONGROW:
184 pMsg = &errMsgWrongRowCol;
185 pEd = m_xEdRowCell.get();
186 break;
187
188 case TABOPERR_NOCOLFORMULA:
189 pMsg = &errMsgNoColFormula;
190 pEd = m_xEdFormulaRange.get();
191 break;
192
193 case TABOPERR_WRONGCOL:
194 pMsg = &errMsgWrongRowCol;
195 pEd = m_xEdColCell.get();
196 break;
197
198 case TABOPERR_NOROWFORMULA:
199 pMsg = &errMsgNoRowFormula;
200 pEd = m_xEdFormulaRange.get();
201 break;
202 }
203
204 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
205 VclMessageType::Error, VclButtonsType::OkCancel, *pMsg));
206 xBox->run();
207 pEd->GrabFocus();
208}
209
210static bool lcl_Parse( const OUString& rString, const ScDocument& rDoc, SCTAB nCurTab,
211 ScRefAddress& rStart, ScRefAddress& rEnd )
212{
213 bool bRet = false;
214 const formula::FormulaGrammar::AddressConvention eConv = rDoc.GetAddressConvention();
215 if ( rString.indexOf(':') != -1 )
216 bRet = ConvertDoubleRef( rDoc, rString, nCurTab, rStart, rEnd, eConv );
217 else
218 {
219 bRet = ConvertSingleRef( rDoc, rString, nCurTab, rStart, eConv );
220 rEnd = rStart;
221 }
222 return bRet;
223}
224
225// Handler:
226
227IMPL_LINK(ScTabOpDlg, BtnHdl, weld::Button&, rBtn, void)void ScTabOpDlg::LinkStubBtnHdl(void * instance, weld::Button
& data) { return static_cast<ScTabOpDlg *>(instance
)->BtnHdl(data); } void ScTabOpDlg::BtnHdl(weld::Button&
rBtn)
228{
229 if (&rBtn == m_xBtnOk.get())
230 {
231 ScTabOpParam::Mode eMode = ScTabOpParam::Column;
232 sal_uInt16 nError = 0;
233
234 // The following code checks:
235 // 1. do the strings contain correct cell references / defined names?
236 // 2. is formula range row if row is empty or column if column is empty
237 // or single reference if both?
238 // 3. is at least one of row or column non-empty?
239
240 if (m_xEdFormulaRange->GetText().isEmpty())
241 nError = TABOPERR_NOFORMULA;
242 else if (m_xEdRowCell->GetText().isEmpty() &&
243 m_xEdColCell->GetText().isEmpty())
244 nError = TABOPERR_NOCOLROW;
245 else if ( !lcl_Parse( m_xEdFormulaRange->GetText(), *pDoc, nCurTab,
246 theFormulaCell, theFormulaEnd ) )
247 nError = TABOPERR_WRONGFORMULA;
248 else
249 {
250 const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
251 if (!m_xEdRowCell->GetText().isEmpty())
252 {
253 if (!ConvertSingleRef( *pDoc, m_xEdRowCell->GetText(), nCurTab,
254 theRowCell, eConv ))
255 nError = TABOPERR_WRONGROW;
256 else
257 {
258 if (m_xEdColCell->GetText().isEmpty() &&
259 theFormulaCell.Col() != theFormulaEnd.Col())
260 nError = TABOPERR_NOCOLFORMULA;
261 else
262 eMode = ScTabOpParam::Row;
263 }
264 }
265 if (!m_xEdColCell->GetText().isEmpty())
266 {
267 if (!ConvertSingleRef( *pDoc, m_xEdColCell->GetText(), nCurTab,
268 theColCell, eConv ))
269 nError = TABOPERR_WRONGCOL;
270 else
271 {
272 if (eMode == ScTabOpParam::Row) // both
273 {
274 eMode = ScTabOpParam::Both;
275 ConvertSingleRef( *pDoc, m_xEdFormulaRange->GetText(), nCurTab,
276 theFormulaCell, eConv );
277 }
278 else if (theFormulaCell.Row() != theFormulaEnd.Row())
279 nError = TABOPERR_NOROWFORMULA;
280 else
281 eMode = ScTabOpParam::Column;
282 }
283 }
284 }
285
286 if (nError)
287 RaiseError( static_cast<ScTabOpErr>(nError) );
288 else
289 {
290 ScTabOpParam aOutParam(theFormulaCell, theFormulaEnd, theRowCell, theColCell, eMode);
291 ScTabOpItem aOutItem( SID_TABOP((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22))
+ 20)) + 18)
, &aOutParam );
292
293 SetDispatcherLock( false );
294 SwitchToDocument();
295 GetBindings().GetDispatcher()->ExecuteList(SID_TABOP((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22))
+ 20)) + 18)
,
296 SfxCallMode::SLOT | SfxCallMode::RECORD,
297 { &aOutItem });
298 response(RET_OK);
299 }
300 }
301 else if (&rBtn == m_xBtnCancel.get())
302 response(RET_CANCEL);
303}
304
305IMPL_LINK( ScTabOpDlg, GetEditFocusHdl, formula::RefEdit&, rCtrl, void )void ScTabOpDlg::LinkStubGetEditFocusHdl(void * instance, formula
::RefEdit& data) { return static_cast<ScTabOpDlg *>
(instance)->GetEditFocusHdl(data); } void ScTabOpDlg::GetEditFocusHdl
(formula::RefEdit& rCtrl)
306{
307 if (&rCtrl == m_xEdFormulaRange.get())
308 m_pEdActive = m_xEdFormulaRange.get();
309 else if (&rCtrl == m_xEdRowCell.get())
310 m_pEdActive = m_xEdRowCell.get();
311 else if (&rCtrl == m_xEdColCell.get())
312 m_pEdActive = m_xEdColCell.get();
313 else
314 m_pEdActive = nullptr;
315
316 if( m_pEdActive )
317 m_pEdActive->SelectAll();
318}
319
320IMPL_LINK( ScTabOpDlg, GetButtonFocusHdl, formula::RefButton&, rCtrl, void )void ScTabOpDlg::LinkStubGetButtonFocusHdl(void * instance, formula
::RefButton& data) { return static_cast<ScTabOpDlg *>
(instance)->GetButtonFocusHdl(data); } void ScTabOpDlg::GetButtonFocusHdl
(formula::RefButton& rCtrl)
321{
322 if (&rCtrl == m_xRBFormulaRange.get())
323 m_pEdActive = m_xEdFormulaRange.get();
324 else if (&rCtrl == m_xRBRowCell.get())
325 m_pEdActive = m_xEdRowCell.get();
326 else if (&rCtrl == m_xRBColCell.get())
327 m_pEdActive = m_xEdColCell.get();
328 else
329 m_pEdActive = nullptr;
330
331 if( m_pEdActive )
332 m_pEdActive->SelectAll();
333}
334
335IMPL_LINK_NOARG(ScTabOpDlg, LoseEditFocusHdl, formula::RefEdit&, void)void ScTabOpDlg::LinkStubLoseEditFocusHdl(void * instance, formula
::RefEdit& data) { return static_cast<ScTabOpDlg *>
(instance)->LoseEditFocusHdl(data); } void ScTabOpDlg::LoseEditFocusHdl
(__attribute__ ((unused)) formula::RefEdit&)
336{
337 bDlgLostFocus = !m_xDialog->has_toplevel_focus();
338}
339
340IMPL_LINK_NOARG(ScTabOpDlg, LoseButtonFocusHdl, formula::RefButton&, void)void ScTabOpDlg::LinkStubLoseButtonFocusHdl(void * instance, formula
::RefButton& data) { return static_cast<ScTabOpDlg *>
(instance)->LoseButtonFocusHdl(data); } void ScTabOpDlg::LoseButtonFocusHdl
(__attribute__ ((unused)) formula::RefButton&)
341{
342 bDlgLostFocus = !m_xDialog->has_toplevel_focus();
343}
344
345/* vim:set shiftwidth=4 softtabstop=4 expandtab: */