clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name strhelper.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 /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/glm -isystem /usr/include/glib-2.0 -isystem /usr/lib64/glib-2.0/include -isystem /usr/include/libmount -isystem /usr/include/blkid -isystem /usr/include/cairo -isystem /usr/include/glib-2.0 -isystem /usr/lib64/glib-2.0/include -isystem /usr/include/pixman-1 -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -isystem /usr/include/libxml2 -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -isystem /usr/include/dbus-1.0 -isystem /usr/lib64/dbus-1.0/include -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -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 VCL_DLLIMPLEMENTATION -D DLLIMPLEMENTATION_UITEST -D CUI_DLL_NAME="libcuilo.so" -D DESKTOP_DETECTOR_DLL_NAME="libdesktop_detectorlo.so" -D TK_DLL_NAME="libtklo.so" -D SYSTEM_ZLIB -D GLM_FORCE_CTOR_INIT -D SK_USER_CONFIG_HEADER=</home/maarten/src/libreoffice/core/config_host/config_skia.h> -D SKIA_DLL -D ENABLE_CUPS -D HAVE_VALGRIND_HEADERS -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/epoxy/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/core -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/effects -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/gpu -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/config -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/ports -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/third_party/vulkan -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/tools/gpu -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia -I /home/maarten/src/libreoffice/core/external/skia/inc/ -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/mdds/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/lcms2/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/workdir/UnpackedTarball/harfbuzz/src -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/graphite/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/workdir/UnpackedTarball/pdfium -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/pdfium/public -D COMPONENT_BUILD -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/libpng -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/libjpeg-turbo -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/vcl/inc -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 -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libxml2 -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/vcl/source/helper/strhelper.cxx
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | #include <strhelper.hxx> |
21 | |
22 | namespace { |
23 | |
24 | bool isSpace( sal_Unicode cChar ) |
25 | { |
26 | return |
27 | cChar == ' ' || cChar == '\t' || |
28 | cChar == '\r' || cChar == '\n' || |
29 | cChar == 0x0c || cChar == 0x0b; |
30 | } |
31 | |
32 | bool isProtect( sal_Unicode cChar ) |
33 | { |
34 | return cChar == '`' || cChar == '\'' || cChar == '"'; |
35 | } |
36 | |
37 | void CopyUntil( char*& pTo, const char*& pFrom, char cUntil, bool bIncludeUntil = false ) |
38 | { |
39 | do |
40 | { |
41 | if( *pFrom == '\\' ) |
42 | { |
43 | pFrom++; |
44 | if( *pFrom ) |
45 | { |
46 | *pTo = *pFrom; |
47 | pTo++; |
48 | } |
49 | } |
50 | else if( bIncludeUntil || ! isProtect( *pFrom ) ) |
51 | { |
52 | *pTo = *pFrom; |
53 | pTo++; |
54 | } |
55 | pFrom++; |
56 | } while( *pFrom && *pFrom != cUntil ); |
57 | |
58 | if( ! isProtect( *pFrom ) || bIncludeUntil ) |
59 | { |
60 | *pTo = *pFrom; |
61 | if( *pTo ) |
62 | pTo++; |
63 | } |
64 | if( *pFrom ) |
65 | pFrom++; |
66 | } |
67 | |
68 | void CopyUntil( sal_Unicode*& pTo, const sal_Unicode*& pFrom, sal_Unicode cUntil, bool bIncludeUntil = false ) |
69 | { |
70 | do |
71 | { |
72 | if( *pFrom == '\\' ) |
73 | { |
74 | pFrom++; |
75 | if( *pFrom ) |
76 | { |
77 | *pTo = *pFrom; |
78 | pTo++; |
79 | } |
80 | } |
81 | else if( bIncludeUntil || ! isProtect( *pFrom ) ) |
82 | { |
83 | *pTo = *pFrom; |
84 | pTo++; |
85 | } |
86 | pFrom++; |
87 | } while( *pFrom && *pFrom != cUntil ); |
88 | |
89 | if( ! isProtect( *pFrom ) || bIncludeUntil ) |
90 | { |
91 | *pTo = *pFrom; |
92 | if( *pTo ) |
93 | pTo++; |
94 | } |
95 | if( *pFrom ) |
96 | pFrom++; |
97 | } |
98 | |
99 | } |
100 | |
101 | namespace psp { |
102 | |
103 | OUString GetCommandLineToken( int nToken, const OUString& rLine ) |
104 | { |
105 | sal_Int32 nLen = rLine.getLength(); |
106 | if( ! nLen ) |
107 | return OUString(); |
108 | |
109 | int nActualToken = 0; |
110 | sal_Unicode* pBuffer = static_cast<sal_Unicode*>(alloca( sizeof(sal_Unicode)*( nLen + 1 ) )); |
111 | const sal_Unicode* pRun = rLine.getStr(); |
112 | sal_Unicode* pLeap = nullptr; |
113 | |
114 | while( *pRun && nActualToken <= nToken ) |
115 | { |
116 | while( *pRun && isSpace( *pRun ) ) |
117 | pRun++; |
118 | pLeap = pBuffer; |
119 | while( *pRun && ! isSpace( *pRun ) ) |
120 | { |
121 | if( *pRun == '\\' ) |
122 | { |
123 | |
124 | pRun++; |
125 | *pLeap = *pRun; |
126 | pLeap++; |
127 | if( *pRun ) |
128 | pRun++; |
129 | } |
130 | else if( *pRun == '`' ) |
131 | CopyUntil( pLeap, pRun, '`' ); |
132 | else if( *pRun == '\'' ) |
133 | CopyUntil( pLeap, pRun, '\'' ); |
134 | else if( *pRun == '"' ) |
135 | CopyUntil( pLeap, pRun, '"' ); |
136 | else |
137 | { |
138 | *pLeap = *pRun; |
139 | pLeap++; |
140 | pRun++; |
141 | } |
142 | } |
143 | if( nActualToken != nToken ) |
144 | pBuffer[0] = 0; |
145 | nActualToken++; |
146 | } |
147 | |
148 | *pLeap = 0; |
149 | |
150 | return OUString(pBuffer); |
151 | } |
152 | |
153 | OString GetCommandLineToken(int nToken, const OString& rLine) |
154 | { |
155 | sal_Int32 nLen = rLine.getLength(); |
156 | if (!nLen) |
| 1 | Assuming 'nLen' is not equal to 0 | |
|
| |
157 | return rLine; |
158 | |
159 | int nActualToken = 0; |
160 | char* pBuffer = static_cast<char*>(alloca( nLen + 1 )); |
161 | const char* pRun = rLine.getStr(); |
162 | char* pLeap = nullptr; |
| 3 | | 'pLeap' initialized to a null pointer value | |
|
163 | |
164 | while( *pRun && nActualToken <= nToken ) |
| 4 | | Assuming the condition is false | |
|
165 | { |
166 | while( *pRun && isSpace( *pRun ) ) |
167 | pRun++; |
168 | pLeap = pBuffer; |
169 | while( *pRun && ! isSpace( *pRun ) ) |
170 | { |
171 | if( *pRun == '\\' ) |
172 | { |
173 | |
174 | pRun++; |
175 | *pLeap = *pRun; |
176 | pLeap++; |
177 | if( *pRun ) |
178 | pRun++; |
179 | } |
180 | else if( *pRun == '`' ) |
181 | CopyUntil( pLeap, pRun, '`' ); |
182 | else if( *pRun == '\'' ) |
183 | CopyUntil( pLeap, pRun, '\'' ); |
184 | else if( *pRun == '"' ) |
185 | CopyUntil( pLeap, pRun, '"' ); |
186 | else |
187 | { |
188 | *pLeap = *pRun; |
189 | pLeap++; |
190 | pRun++; |
191 | } |
192 | } |
193 | if( nActualToken != nToken ) |
194 | pBuffer[0] = 0; |
195 | nActualToken++; |
196 | } |
197 | |
198 | *pLeap = 0; |
| 5 | | Dereference of null pointer (loaded from variable 'pLeap') |
|
199 | |
200 | return pBuffer; |
201 | } |
202 | |
203 | int GetCommandLineTokenCount(const OUString& rLine) |
204 | { |
205 | if (rLine.isEmpty()) |
206 | return 0; |
207 | |
208 | int nTokenCount = 0; |
209 | const sal_Unicode *pRun = rLine.getStr(); |
210 | |
211 | while( *pRun ) |
212 | { |
213 | while( *pRun && isSpace( *pRun ) ) |
214 | pRun++; |
215 | if( ! *pRun ) |
216 | break; |
217 | while( *pRun && ! isSpace( *pRun ) ) |
218 | { |
219 | if( *pRun == '\\' ) |
220 | { |
221 | |
222 | pRun++; |
223 | if( *pRun ) |
224 | pRun++; |
225 | } |
226 | else if( *pRun == '`' ) |
227 | { |
228 | do pRun++; while( *pRun && *pRun != '`' ); |
229 | if( *pRun ) |
230 | pRun++; |
231 | } |
232 | else if( *pRun == '\'' ) |
233 | { |
234 | do pRun++; while( *pRun && *pRun != '\'' ); |
235 | if( *pRun ) |
236 | pRun++; |
237 | } |
238 | else if( *pRun == '"' ) |
239 | { |
240 | do pRun++; while( *pRun && *pRun != '"' ); |
241 | if( *pRun ) |
242 | pRun++; |
243 | } |
244 | else |
245 | pRun++; |
246 | } |
247 | nTokenCount++; |
248 | } |
249 | |
250 | return nTokenCount; |
251 | } |
252 | |
253 | OUString WhitespaceToSpace( const OUString& rLine, bool bProtect ) |
254 | { |
255 | sal_Int32 nLen = rLine.getLength(); |
256 | if( ! nLen ) |
257 | return OUString(); |
258 | |
259 | sal_Unicode *pBuffer = static_cast<sal_Unicode*>(alloca( sizeof(sal_Unicode)*(nLen + 1) )); |
260 | const sal_Unicode *pRun = rLine.getStr(); |
261 | sal_Unicode *pLeap = pBuffer; |
262 | |
263 | while( *pRun ) |
264 | { |
265 | if( *pRun && isSpace( *pRun ) ) |
266 | { |
267 | *pLeap = ' '; |
268 | pLeap++; |
269 | pRun++; |
270 | } |
271 | while( *pRun && isSpace( *pRun ) ) |
272 | pRun++; |
273 | while( *pRun && ! isSpace( *pRun ) ) |
274 | { |
275 | if( *pRun == '\\' ) |
276 | { |
277 | |
278 | pRun++; |
279 | *pLeap = *pRun; |
280 | pLeap++; |
281 | if( *pRun ) |
282 | pRun++; |
283 | } |
284 | else if( bProtect && *pRun == '`' ) |
285 | CopyUntil( pLeap, pRun, '`', true ); |
286 | else if( bProtect && *pRun == '\'' ) |
287 | CopyUntil( pLeap, pRun, '\'', true ); |
288 | else if( bProtect && *pRun == '"' ) |
289 | CopyUntil( pLeap, pRun, '"', true ); |
290 | else |
291 | { |
292 | *pLeap = *pRun; |
293 | ++pLeap; |
294 | ++pRun; |
295 | } |
296 | } |
297 | } |
298 | |
299 | *pLeap = 0; |
300 | |
301 | |
302 | if (pLeap > pBuffer) |
303 | { |
304 | pLeap--; |
305 | if( *pLeap == ' ' ) |
306 | *pLeap = 0; |
307 | } |
308 | |
309 | return OUString(*pBuffer == ' ' ? pBuffer+1 : pBuffer); |
310 | } |
311 | |
312 | OString WhitespaceToSpace(const OString& rLine) |
313 | { |
314 | sal_Int32 nLen = rLine.getLength(); |
315 | if (!nLen) |
316 | return rLine; |
317 | |
318 | char *pBuffer = static_cast<char*>(alloca( nLen + 1 )); |
319 | const char *pRun = rLine.getStr(); |
320 | char *pLeap = pBuffer; |
321 | |
322 | while( *pRun ) |
323 | { |
324 | if( *pRun && isSpace( *pRun ) ) |
325 | { |
326 | *pLeap = ' '; |
327 | pLeap++; |
328 | pRun++; |
329 | } |
330 | while( *pRun && isSpace( *pRun ) ) |
331 | pRun++; |
332 | while( *pRun && ! isSpace( *pRun ) ) |
333 | { |
334 | if( *pRun == '\\' ) |
335 | { |
336 | |
337 | pRun++; |
338 | *pLeap = *pRun; |
339 | pLeap++; |
340 | if( *pRun ) |
341 | pRun++; |
342 | } |
343 | else if( *pRun == '`' ) |
344 | CopyUntil( pLeap, pRun, '`', true ); |
345 | else if( *pRun == '\'' ) |
346 | CopyUntil( pLeap, pRun, '\'', true ); |
347 | else if( *pRun == '"' ) |
348 | CopyUntil( pLeap, pRun, '"', true ); |
349 | else |
350 | { |
351 | *pLeap = *pRun; |
352 | ++pLeap; |
353 | ++pRun; |
354 | } |
355 | } |
356 | } |
357 | |
358 | *pLeap = 0; |
359 | |
360 | |
361 | pLeap--; |
362 | if( *pLeap == ' ' ) |
363 | *pLeap = 0; |
364 | |
365 | return *pBuffer == ' ' ? pBuffer+1 : pBuffer; |
366 | } |
367 | |
368 | } |
369 | |
370 | |