clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name UnoNamespaceMap.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 SVX_DLLIMPLEMENTATION -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/svx/inc -I /home/maarten/src/libreoffice/core/svx/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/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -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/svx/source/unodraw/UnoNamespaceMap.cxx
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | #include <climits> |
22 | #include <set> |
23 | |
24 | #include <svx/UnoNamespaceMap.hxx> |
25 | #include <com/sun/star/container/XNameAccess.hpp> |
26 | #include <com/sun/star/lang/XServiceInfo.hpp> |
27 | |
28 | #include <comphelper/sequence.hxx> |
29 | #include <cppuhelper/implbase.hxx> |
30 | #include <cppuhelper/supportsservice.hxx> |
31 | #include <svl/itempool.hxx> |
32 | #include <editeng/xmlcnitm.hxx> |
33 | |
34 | using namespace ::cppu; |
35 | using namespace ::com::sun::star; |
36 | using namespace ::com::sun::star::uno; |
37 | using namespace ::com::sun::star::container; |
38 | using namespace ::com::sun::star::lang; |
39 | |
40 | namespace svx |
41 | { |
42 | namespace { |
43 | |
44 | |
45 | |
46 | |
47 | class NamespaceMap : public WeakImplHelper< XNameAccess, XServiceInfo > |
48 | { |
49 | private: |
50 | sal_uInt16* mpWhichIds; |
51 | SfxItemPool* mpPool; |
52 | |
53 | public: |
54 | NamespaceMap( sal_uInt16* pWhichIds, SfxItemPool* pPool ); |
55 | |
56 | |
57 | virtual Any SAL_CALL getByName( const OUString& aName ) override; |
58 | virtual Sequence< OUString > SAL_CALL getElementNames( ) override; |
59 | virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override; |
60 | |
61 | |
62 | virtual Type SAL_CALL getElementType( ) override; |
63 | virtual sal_Bool SAL_CALL hasElements( ) override; |
64 | |
65 | |
66 | virtual OUString SAL_CALL getImplementationName( ) override; |
67 | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; |
68 | virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; |
69 | }; |
70 | |
71 | } |
72 | |
73 | Reference< XInterface > NamespaceMap_createInstance( sal_uInt16* pWhichIds, SfxItemPool* pPool ) |
74 | { |
75 | return static_cast<XWeak*>(new NamespaceMap( pWhichIds, pPool )); |
76 | } |
77 | |
78 | static Sequence< OUString > NamespaceMap_getSupportedServiceNames() |
79 | throw() |
80 | { |
81 | Sequence<OUString> aSupportedServiceNames { "com.sun.star.xml.NamespaceMap" }; |
82 | return aSupportedServiceNames; |
83 | } |
84 | |
85 | static OUString NamespaceMap_getImplementationName() |
86 | throw() |
87 | { |
88 | return "com.sun.star.comp.Svx.NamespaceMap"; |
89 | } |
90 | |
91 | namespace { |
92 | |
93 | class NamespaceIteratorImpl |
94 | { |
95 | private: |
96 | SfxItemPool* mpPool; |
97 | |
98 | sal_uInt16* mpWhichId; |
99 | |
100 | std::vector<const SvXMLAttrContainerItem*> mvItems; |
101 | sal_Int32 mnItem; |
102 | |
103 | const SvXMLAttrContainerItem* mpCurrentAttr; |
104 | sal_uInt16 mnCurrentAttr; |
105 | |
106 | public: |
107 | |
108 | NamespaceIteratorImpl( sal_uInt16* pWhichIds, SfxItemPool* pPool ); |
109 | |
110 | bool next( OUString& rPrefix, OUString& rURL ); |
111 | }; |
112 | |
113 | } |
114 | } |
115 | |
116 | using namespace ::svx; |
117 | |
118 | |
119 | NamespaceIteratorImpl::NamespaceIteratorImpl( sal_uInt16* pWhichIds, SfxItemPool* pPool ) |
120 | { |
121 | mpPool = pPool; |
122 | mpCurrentAttr = nullptr; |
123 | mnCurrentAttr = 0; |
124 | |
125 | mpWhichId = pWhichIds; |
126 | |
127 | mnItem = -1; |
128 | if (mpWhichId && (0 != *mpWhichId) && mpPool) |
129 | { |
130 | mvItems.reserve(mpPool->GetItemCount2( *mpWhichId )); |
131 | for (const SfxPoolItem* pItem : mpPool->GetItemSurrogates( *mpWhichId )) |
132 | mvItems.push_back(static_cast<const SvXMLAttrContainerItem*>(pItem)); |
133 | } |
134 | } |
135 | |
136 | bool NamespaceIteratorImpl::next( OUString& rPrefix, OUString& rURL ) |
137 | { |
138 | |
139 | if( mpCurrentAttr && (mnCurrentAttr != USHRT_MAX) ) |
140 | { |
141 | rPrefix = mpCurrentAttr->GetPrefix( mnCurrentAttr ); |
142 | rURL = mpCurrentAttr->GetNamespace( mnCurrentAttr ); |
143 | |
144 | mnCurrentAttr = mpCurrentAttr->GetNextNamespaceIndex( mnCurrentAttr ); |
145 | return true; |
146 | } |
147 | |
148 | |
149 | mpCurrentAttr = nullptr; |
150 | mnItem++; |
151 | |
152 | |
153 | if( mnItem == static_cast<sal_Int32>(mvItems.size()) ) |
| 2 | | Assuming the condition is true | |
|
| |
154 | { |
155 | mpWhichId++; |
| 4 | | Null pointer value stored to 'aIter.mpWhichId' | |
|
156 | |
157 | |
158 | if( 0 == *mpWhichId ) |
| 5 | | Dereference of null pointer (loaded from field 'mpWhichId') |
|
159 | return false; |
160 | |
161 | mnItem = -1; |
162 | mvItems.clear(); |
163 | if (mpPool) |
164 | { |
165 | mvItems.reserve(mpPool->GetItemCount2( *mpWhichId )); |
166 | for (const SfxPoolItem* pItem2 : mpPool->GetItemSurrogates( *mpWhichId )) |
167 | mvItems.push_back(static_cast<const SvXMLAttrContainerItem*>(pItem2)); |
168 | } |
169 | return next( rPrefix, rURL ); |
170 | } |
171 | |
172 | auto pItem = mvItems[mnItem]; |
173 | |
174 | if( pItem->GetAttrCount() > 0 ) |
175 | { |
176 | mpCurrentAttr = pItem; |
177 | mnCurrentAttr = pItem->GetFirstNamespaceIndex(); |
178 | } |
179 | return next( rPrefix, rURL ); |
180 | } |
181 | |
182 | |
183 | NamespaceMap::NamespaceMap( sal_uInt16* pWhichIds, SfxItemPool* pPool ) |
184 | : mpWhichIds( pWhichIds ), mpPool( pPool ) |
185 | { |
186 | } |
187 | |
188 | |
189 | Any SAL_CALL NamespaceMap::getByName( const OUString& aName ) |
190 | { |
191 | NamespaceIteratorImpl aIter( mpWhichIds, mpPool ); |
192 | |
193 | OUString aPrefix; |
194 | OUString aURL; |
195 | |
196 | bool bFound; |
197 | |
198 | do |
199 | { |
200 | bFound = aIter.next( aPrefix, aURL ); |
201 | } |
202 | while( bFound && (aPrefix != aName ) ); |
203 | |
204 | if( !bFound ) |
205 | throw NoSuchElementException(); |
206 | |
207 | return makeAny( aURL ); |
208 | } |
209 | |
210 | Sequence< OUString > SAL_CALL NamespaceMap::getElementNames() |
211 | { |
212 | NamespaceIteratorImpl aIter( mpWhichIds, mpPool ); |
213 | |
214 | OUString aPrefix; |
215 | OUString aURL; |
216 | |
217 | std::set< OUString > aPrefixSet; |
218 | |
219 | while( aIter.next( aPrefix, aURL ) ) |
220 | aPrefixSet.insert( aPrefix ); |
221 | |
222 | return comphelper::containerToSequence(aPrefixSet); |
223 | } |
224 | |
225 | sal_Bool SAL_CALL NamespaceMap::hasByName( const OUString& aName ) |
226 | { |
227 | NamespaceIteratorImpl aIter( mpWhichIds, mpPool ); |
228 | |
229 | OUString aPrefix; |
230 | OUString aURL; |
231 | |
232 | bool bFound; |
233 | |
234 | do |
235 | { |
236 | bFound = aIter.next( aPrefix, aURL ); |
237 | } |
238 | while( bFound && (aPrefix != aName ) ); |
239 | |
240 | return bFound; |
241 | } |
242 | |
243 | |
244 | Type SAL_CALL NamespaceMap::getElementType() |
245 | { |
246 | return ::cppu::UnoType<OUString>::get(); |
247 | } |
248 | |
249 | sal_Bool SAL_CALL NamespaceMap::hasElements() |
250 | { |
251 | NamespaceIteratorImpl aIter( mpWhichIds, mpPool ); |
252 | |
253 | OUString aPrefix; |
254 | OUString aURL; |
255 | |
256 | return aIter.next( aPrefix, aURL ); |
| 1 | Calling 'NamespaceIteratorImpl::next' | |
|
257 | } |
258 | |
259 | |
260 | OUString SAL_CALL NamespaceMap::getImplementationName( ) |
261 | { |
262 | return NamespaceMap_getImplementationName(); |
263 | } |
264 | |
265 | sal_Bool SAL_CALL NamespaceMap::supportsService( const OUString& serviceName ) |
266 | { |
267 | return cppu::supportsService( this, serviceName ); |
268 | } |
269 | |
270 | Sequence< OUString > SAL_CALL NamespaceMap::getSupportedServiceNames( ) |
271 | { |
272 | return NamespaceMap_getSupportedServiceNames(); |
273 | } |
274 | |
275 | |