Bug Summary

File:home/maarten/src/libreoffice/core/lotuswordpro/source/filter/lwptoc.cxx
Warning:line 328, column 16
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 lwptoc.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/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/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 -I /home/maarten/src/libreoffice/core/lotuswordpro/inc -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/lotuswordpro/source/filter/lwptoc.cxx

/home/maarten/src/libreoffice/core/lotuswordpro/source/filter/lwptoc.cxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
6 *
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
9 *
10 * Sun Microsystems Inc., October, 2000
11 *
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 *
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 *
31 *
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
38 *
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
45 *
46 * The Initial Developer of the Original Code is: IBM Corporation
47 *
48 * Copyright: 2008 by IBM Corporation
49 *
50 * All Rights Reserved.
51 *
52 * Contributor(s): _______________________________________
53 *
54 *
55 ************************************************************************/
56/**
57 * @file
58 * For LWP filter architecture prototype - TOC related object
59 */
60
61#include "lwptoc.hxx"
62#include <lwpfoundry.hxx>
63#include "lwpdoc.hxx"
64#include "lwpframelayout.hxx"
65#include <lwpglobalmgr.hxx>
66
67#include <xfilter/xftextstyle.hxx>
68#include <xfilter/xfstylemanager.hxx>
69#include <xfilter/xfparastyle.hxx>
70#include <xfilter/xfindex.hxx>
71#include <xfilter/xffloatframe.hxx>
72#include <xfilter/xfframe.hxx>
73
74LwpTocSuperLayout::LwpTocSuperLayout(LwpObjectHeader const &objHdr, LwpSvStream* pStrm)
75 : LwpSuperTableLayout(objHdr, pStrm)
76 , m_nFrom(0)
77 , m_pCont(nullptr)
78{
79}
80
81LwpTocSuperLayout::~LwpTocSuperLayout()
82{
83}
84
85/**
86 * @short Read TOCSUPERTABLELAYOUT object
87 * @return none
88 */
89void LwpTocSuperLayout::Read()
90{
91 LwpSuperTableLayout::Read();
92 m_TextMarker.Read(m_pObjStrm.get());
93 m_ParentName.Read(m_pObjStrm.get());
94 m_DivisionName.Read(m_pObjStrm.get());
95 m_SectionName.Read(m_pObjStrm.get());
96 m_nFrom = m_pObjStrm->QuickReaduInt16();
97
98 m_SearchItems.Read(m_pObjStrm.get());
99
100 sal_uInt16 count = m_pObjStrm->QuickReaduInt16();
101 if (count > MAX_LEVELS)
102 throw std::range_error("corrupt LwpTocSuperLayout");
103 for (sal_uInt16 i = 0; i < count; ++i)
104 m_DestName[i].Read(m_pObjStrm.get());
105
106 count = m_pObjStrm->QuickReaduInt16();
107 if (count > MAX_LEVELS)
108 throw std::range_error("corrupt LwpTocSuperLayout");
109 for (sal_uInt16 i = 0; i < count; ++i)
110 m_DestPGName[i].Read(m_pObjStrm.get());
111
112 count = m_pObjStrm->QuickReaduInt16();
113 if (count > MAX_LEVELS)
114 throw std::range_error("corrupt LwpTocSuperLayout");
115 for (sal_uInt16 i = 0; i < count; ++i)
116 m_nFlags[i] = m_pObjStrm->QuickReaduInt32();
117
118 m_pObjStrm->SkipExtra();
119}
120/**
121 * @short Register style of TOC
122 * @return none
123 */
124void LwpTocSuperLayout::RegisterStyle()
125{
126 LwpSuperTableLayout::RegisterStyle();
127
128 // Get font info of default text style and set into tab style
129 const LwpObjectID *pDefaultTextStyle = m_pFoundry ? m_pFoundry->GetDefaultTextStyle() : nullptr;
130 XFParaStyle* pBaseStyle = pDefaultTextStyle ? dynamic_cast<XFParaStyle*>(m_pFoundry->GetStyleManager()->GetStyle(*pDefaultTextStyle)) : nullptr;
131 std::unique_ptr<XFTextStyle> pTextStyle(new XFTextStyle);
132 if (pBaseStyle)
133 pTextStyle->SetFont(pBaseStyle->GetFont()); // who delete this font?????
134 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
135 m_TabStyleName = pXFStyleManager->AddStyle(std::move(pTextStyle)).m_pStyle->GetStyleName();
136
137}
138/**
139 * @short Convert TOC
140 * @param pCont - container
141 * @return none
142 */
143void LwpTocSuperLayout::XFConvert(XFContentContainer* pCont)
144{
145 rtl::Reference<XFIndex> xToc(new XFIndex);
146
147 xToc->SetProtected(false);
148 xToc->SetIndexType(enumXFIndexTOC);
149
150 // add TOC template
151 for (sal_uInt16 i = 1; i<= MAX_LEVELS; i++)
1
Loop condition is true. Entering loop body
152 {
153 LwpTocLevelData * pLevel = GetSearchLevelPtr(i);
2
Calling 'LwpTocSuperLayout::GetSearchLevelPtr'
11
Returning from 'LwpTocSuperLayout::GetSearchLevelPtr'
154 XFIndexTemplate * pTemplate = new XFIndexTemplate();
155
156 if(!pLevel
11.1
'pLevel' is non-null
11.1
'pLevel' is non-null
)
12
Taking false branch
157 {
158 // add a blank template so that SODC won't add default style to this level
159 xToc->AddTemplate(OUString::number(i), OUString(), pTemplate);
160 continue;
161 }
162
163 bool bInserted = false;
164 do
165 {
166 // One level has 1 template
167 if (!bInserted
12.1
'bInserted' is false
12.1
'bInserted' is false
)
13
Taking true branch
168 {
169 pTemplate->SetLevel(OUString::number(i));
170 if(pLevel->GetUseLeadingText())
14
Taking false branch
171 {
172 pTemplate->AddEntry(enumXFIndexTemplateChapter, pLevel->GetSearchStyle());
173 }
174 if(pLevel->GetUseText())
15
Taking false branch
175 {
176 pTemplate->AddEntry(enumXFIndexTemplateText, pLevel->GetSearchStyle());
177 }
178 if(GetUsePageNumber(i))
16
Taking false branch
179 {
180 sal_uInt16 nLeaderType = GetSeparatorType(i);
181 if (GetRightAlignPageNumber(i))
182 {
183 char cSep = ' ';
184 switch(nLeaderType)
185 {
186 default: // go through
187 case NONE: // no leaders
188 cSep = ' ';
189 break;
190 case LEADERDOTS:
191 cSep = '.';
192 break;
193 case LEADERDASHES:
194 cSep = '-';
195 break;
196 case LEADERUNDERLINE:
197 cSep = '_';
198 break;
199 }
200
201 pTemplate->AddTabEntry(enumXFTabRight, 0, cSep, 'd', m_TabStyleName);
202 }
203 else
204 {
205 OUString sSep;
206 switch(nLeaderType)
207 {
208 default: // go through
209 case NONE: // no leaders
210 sSep = " ";
211 break;
212 case SEPARATORCOMMA:
213 sSep = ", ";
214 break;
215 case SEPARATORDOTS:
216 sSep = "...";
217 break;
218 }
219 pTemplate->AddTextEntry(sSep, m_TabStyleName);
220 }
221 //"TOC Page Number Text Style" style always exists in Word Pro file
222 pTemplate->AddEntry(enumXFIndexTemplatePage, "TOC Page Number Text Style");
223 }
224
225 xToc->AddTemplate(OUString::number(static_cast<sal_Int32>(i)), m_pFoundry->FindActuralStyleName(pLevel->GetSearchStyle()), pTemplate);
226 bInserted = true;
227 }
228
229 // 1 style in WordPro may be mapped to several styles in SODC
230 LwpDocument * pDocument = m_pFoundry->GetDocument()->GetRootDocument();
231 AddSourceStyle(xToc.get(), pLevel, pDocument->GetFoundry());
17
Calling 'LwpTocSuperLayout::AddSourceStyle'
232
233 // one level may have several corresponding Styles
234 pLevel = GetNextSearchLevelPtr(i, pLevel); // find next LwpTocLevelData which is same index
235 }while (pLevel != nullptr);
236 }
237
238 m_pCont = pCont;
239 // add TOC content
240 LwpSuperTableLayout::XFConvert(xToc.get());
241
242 rtl::Reference<LwpVirtualLayout> xContainer(GetContainerLayout());
243 if (!xContainer.is())
244 return;
245
246 // if current TOC is located in a cell, we must add a frame between upper level container and TOC
247 if (!xContainer->IsCell())
248 {
249 pCont->Add(xToc.get());
250 }
251}
252
253/**
254 * @short convert frame which anchor to page
255 * @param pCont -
256 * @return
257 */
258void LwpTocSuperLayout::XFConvertFrame(XFContentContainer* pCont, sal_Int32 nStart, sal_Int32 nEnd, bool bAll)
259{
260 if (!m_pFrame)
261 return;
262
263 rtl::Reference<XFFrame> xXFFrame;
264 if(nEnd < nStart)
265 {
266 xXFFrame.set(new XFFrame);
267 }
268 else
269 {
270 xXFFrame.set(new XFFloatFrame(nStart, nEnd, bAll));
271 }
272
273 m_pFrame->Parse(xXFFrame.get(), static_cast<sal_uInt16>(nStart));
274
275 //parse table, and add table to frame or TOC
276 LwpTableLayout * pTableLayout = GetTableLayout();
277 if (!pTableLayout)
278 return;
279
280 XFContentContainer* pTableContainer = xXFFrame.get();
281 // if *this is a TOCSuperTableLayout and it's located in a cell
282 // add the frame to upper level and add TOCSuperTableLayout into the frame
283 rtl::Reference<LwpVirtualLayout> xContainer(GetContainerLayout());
284 if (!xContainer.is())
285 return;
286 if (xContainer->IsCell())
287 {
288 pTableContainer = pCont; // TOC contain table directly
289 xXFFrame->Add(pCont);
290 m_pCont->Add(xXFFrame.get());
291 }
292 else
293 {
294 //add frame to the container
295 pCont->Add(xXFFrame.get());
296 }
297 pTableLayout->XFConvert(pTableContainer);
298
299}
300
301/**
302 * @short Add source style into TOC
303 * @param pToc - TOC pointer
304 * @param pLevel - TOC level data
305 * @param pFoundry - foundry pointer
306 * @return sal_Bool
307 */
308void LwpTocSuperLayout::AddSourceStyle(XFIndex* pToc, LwpTocLevelData * pLevel, LwpFoundry * pFoundry)
309{
310 if (!pLevel
17.1
'pLevel' is non-null
17.1
'pLevel' is non-null
)
18
Taking false branch
311 {
312 return;
313 }
314
315 OUString sLwpStyleName = pLevel->GetSearchStyle();
316
317 if (!pFoundry)
19
Assuming 'pFoundry' is non-null
20
Taking false branch
318 return;
319
320 LwpDocument * pDoc = pFoundry->GetDocument();
21
'pDoc' initialized here
321 if (pDoc && pDoc->IsChildDoc())
22
Assuming 'pDoc' is null
322 {
323 OUString sSodcStyleName = pFoundry->FindActuralStyleName(sLwpStyleName);
324 pToc->AddTocSource(pLevel->GetLevel(), sSodcStyleName);
325 }
326 else
327 {
328 pDoc = pDoc->GetFirstDivision();
23
Called C++ object pointer is null
329 while (pDoc)
330 {
331 AddSourceStyle(pToc, pLevel, pDoc->GetFoundry() );
332 pDoc = pDoc->GetNextDivision();
333 }
334 }
335}
336
337/**
338 * @short Get whether page number is right alignment
339 * @param index - TOC level
340 * @return sal_Bool
341 */
342bool LwpTocSuperLayout::GetRightAlignPageNumber(sal_uInt16 index)
343{
344 if (index < MAX_LEVELS)
345 return (m_nFlags[index] & TS_RIGHTALIGN) != 0;
346 return false;
347}
348/**
349 * @short Get whether page number is used in TOC entries
350 * @param index - TOC level
351 * @return sal_Bool
352 */
353bool LwpTocSuperLayout::GetUsePageNumber(sal_uInt16 index)
354{
355 if (index < MAX_LEVELS)
356 return (m_nFlags[index] & TS_PAGENUMBER) != 0;
357 return false;
358}
359/**
360 * @short Get what is used for separator
361 * @param index - TOC level
362 * @return sal_uInt16 - separator type
363 */
364sal_uInt16 LwpTocSuperLayout::GetSeparatorType(sal_uInt16 index)
365{
366 if (index >= MAX_LEVELS)
367 return NONE;
368
369 sal_uInt16 Flag = static_cast<sal_uInt16>(m_nFlags[index]);
370
371 if (Flag & TS_LEADERDOTS)
372 return LEADERDOTS;
373 else if (Flag & TS_LEADERDASHES)
374 return LEADERDASHES;
375 else if (Flag & TS_LEADERUNDERLINE)
376 return LEADERUNDERLINE;
377 else if (Flag & TS_SEPARATORCOMMA)
378 return SEPARATORCOMMA;
379 else if (Flag & TS_SEPARATORDOTS)
380 return SEPARATORDOTS;
381 else
382 return NONE;
383}
384
385/**
386 * @short Get TOCLEVELDATA obj
387 * @param index - TOC level
388 * @return LwpTocLevelData * - pointer to TOCLEVELDATA obj
389 */
390LwpTocLevelData * LwpTocSuperLayout::GetSearchLevelPtr(sal_uInt16 index)
391{
392 LwpObjectID * pID = &m_SearchItems.GetHead(); // not necessary to check pID NULL or not
393 LwpTocLevelData * pObj = dynamic_cast<LwpTocLevelData *>(pID->obj().get());
3
Calling '~Reference'
6
Returning from '~Reference'
394
395 while(pObj)
7
Loop condition is true. Entering loop body
396 {
397 if(pObj->GetLevel()== index)
8
Assuming the condition is true
9
Taking true branch
398 {
399 return pObj;
10
Returning pointer (loaded from 'pObj'), which participates in a condition later
400 }
401
402 pID = &pObj->GetNext(); // not necessary to check pID NULL or not
403 pObj = dynamic_cast<LwpTocLevelData *>(pID->obj().get());
404 }
405
406 return nullptr;
407}
408/**
409 * @short Get next TOCLEVELDATA obj from current position
410 * @param index - TOC level
411 * @param pCurData - current LwpTocLevelData
412 * @return LwpTocLevelData * - pointer to TOCLEVELDATA obj
413 */
414LwpTocLevelData * LwpTocSuperLayout::GetNextSearchLevelPtr(sal_uInt16 index, LwpTocLevelData * pCurData)
415{
416 LwpObjectID * pID = &pCurData->GetNext();
417 LwpTocLevelData * pObj = dynamic_cast<LwpTocLevelData *>(pID->obj().get());
418
419 while(pObj)
420 {
421 if(pObj->GetLevel()== index)
422 {
423 return pObj;
424 }
425
426 pID = &pObj->GetNext(); // not necessary to check pID NULL or not
427 pObj = dynamic_cast<LwpTocLevelData *>(pID->obj().get());
428 }
429
430 return nullptr;
431}
432
433LwpTocLevelData::LwpTocLevelData(LwpObjectHeader const &objHdr, LwpSvStream* pStrm)
434 : LwpDLVList(objHdr, pStrm), m_nFlags(0), m_nLevel(0)
435{
436}
437LwpTocLevelData::~LwpTocLevelData()
438{
439}
440/**
441 * @short Register style
442 * @param
443 * @return
444 */
445void LwpTocLevelData::RegisterStyle()
446{
447}
448/**
449 * @short Convert
450 * @param pCont - container
451 * @return none
452 */
453void LwpTocLevelData::XFConvert(XFContentContainer* /*pCont*/)
454{
455}
456/**
457 * @short Read TOCLEVELDATA obj
458 * @param
459 * @return
460 */
461void LwpTocLevelData::Read()
462{
463 LwpDLVList::Read();
464 m_nFlags = m_pObjStrm->QuickReaduInt16();
465 m_nLevel = m_pObjStrm->QuickReaduInt16();
466 m_SearchName.Read(m_pObjStrm.get());
467
468 m_pObjStrm->SkipExtra();
469}
470
471/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

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#ifndef INCLUDED_RTL_REF_HXX
21#define INCLUDED_RTL_REF_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <functional>
28#ifdef LIBO_INTERNAL_ONLY1
29#include <type_traits>
30#endif
31
32#include "sal/types.h"
33
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
48 /** Constructor...
49 */
50 Reference()
51 : m_pBody (NULL__null)
52 {}
53
54
55 /** Constructor...
56 */
57 Reference (reference_type * pBody, __sal_NoAcquire)
58 : m_pBody (pBody)
59 {
60 }
61
62 /** Constructor...
63 */
64 Reference (reference_type * pBody)
65 : m_pBody (pBody)
66 {
67 if (m_pBody)
68 m_pBody->acquire();
69 }
70
71 /** Copy constructor...
72 */
73 Reference (const Reference<reference_type> & handle)
74 : m_pBody (handle.m_pBody)
75 {
76 if (m_pBody)
77 m_pBody->acquire();
78 }
79
80#ifdef LIBO_INTERNAL_ONLY1
81 /** Move constructor...
82 */
83 Reference (Reference<reference_type> && handle) noexcept
84 : m_pBody (handle.m_pBody)
85 {
86 handle.m_pBody = nullptr;
87 }
88#endif
89
90#if defined LIBO_INTERNAL_ONLY1
91 /** Up-casting conversion constructor: Copies interface reference.
92
93 Does not work for up-casts to ambiguous bases.
94
95 @param rRef another reference
96 */
97 template< class derived_type >
98 inline Reference(
99 const Reference< derived_type > & rRef,
100 std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
101 : m_pBody (rRef.get())
102 {
103 if (m_pBody)
104 m_pBody->acquire();
105 }
106#endif
107
108 /** Destructor...
109 */
110 ~Reference() COVERITY_NOEXCEPT_FALSE
111 {
112 if (m_pBody)
4
Assuming field 'm_pBody' is non-null
5
Taking true branch
113 m_pBody->release();
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody)
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */