Bug Summary

File:sal/osl/all/filepath.c
Location:line 61, column 14
Description:Access to field 'length' results in a dereference of a null pointer (loaded from variable 'ustrPath')

Annotated Source Code

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 <osl/file.h>
21#include <rtl/ustring.h>
22
23static sal_uInt32 SAL_CALL osl_defCalcTextWidth( rtl_uString *ustrText )
24{
25 return ustrText ? ustrText->length : 0;
4
Assuming 'ustrText' is null
5
'?' condition is false
26}
27
28
29oslFileError SAL_CALL osl_abbreviateSystemPath( rtl_uString *ustrSystemPath, rtl_uString **pustrCompacted, sal_uInt32 uMaxWidth, oslCalcTextWidthFunc pfnCalcWidth )
30{
31 oslFileError error = osl_File_E_None;
32 rtl_uString *ustrPath = NULL((void*)0);
33 rtl_uString *ustrFile = NULL((void*)0);
34 sal_uInt32 uPathWidth, uFileWidth;
35
36 if ( !pfnCalcWidth )
1
Taking true branch
37 pfnCalcWidth = osl_defCalcTextWidth;
38
39 {
40 sal_Int32 iLastSlash = rtl_ustr_lastIndexOfChar_WithLength( ustrSystemPath->buffer, ustrSystemPath->length, SAL_PATHDELIMITER'/' );
41
42 if ( iLastSlash >= 0 )
2
Taking false branch
43 {
44 rtl_uString_newFromStr_WithLength( &ustrPath, ustrSystemPath->buffer, iLastSlash );
45 rtl_uString_newFromStr_WithLength( &ustrFile, &ustrSystemPath->buffer[iLastSlash], ustrSystemPath->length - iLastSlash );
46 }
47 else
48 {
49 rtl_uString_new( &ustrPath );
50 rtl_uString_newFromString( &ustrFile, ustrSystemPath );
51 }
52 }
53
54 uPathWidth = pfnCalcWidth( ustrPath );
3
Calling 'osl_defCalcTextWidth'
6
Returning from 'osl_defCalcTextWidth'
55 uFileWidth = pfnCalcWidth( ustrFile );
56
57 /* First abbreviate the directory component of the path */
58
59 while ( uPathWidth + uFileWidth > uMaxWidth )
7
Loop condition is true. Entering loop body
60 {
61 if ( ustrPath->length > 3 )
8
Access to field 'length' results in a dereference of a null pointer (loaded from variable 'ustrPath')
62 {
63 ustrPath->length--;
64 ustrPath->buffer[ustrPath->length-3] = '.';
65 ustrPath->buffer[ustrPath->length-2] = '.';
66 ustrPath->buffer[ustrPath->length-1] = '.';
67 ustrPath->buffer[ustrPath->length] = 0;
68
69 uPathWidth = pfnCalcWidth( ustrPath );
70 }
71 else
72 break;
73 }
74
75 /* Now abbreviate file component */
76
77 while ( uPathWidth + uFileWidth > uMaxWidth )
78 {
79 if ( ustrFile->length > 4 )
80 {
81 ustrFile->length--;
82 ustrFile->buffer[ustrFile->length-3] = '.';
83 ustrFile->buffer[ustrFile->length-2] = '.';
84 ustrFile->buffer[ustrFile->length-1] = '.';
85 ustrFile->buffer[ustrFile->length] = 0;
86
87 uFileWidth = pfnCalcWidth( ustrFile );
88 }
89 else
90 break;
91 }
92
93 rtl_uString_newConcat( pustrCompacted, ustrPath, ustrFile );
94
95 /* Event now if path was compacted to ".../..." it can be to large */
96
97 uPathWidth += uFileWidth;
98
99 while ( uPathWidth > uMaxWidth )
100 {
101 (*pustrCompacted)->length--;
102 (*pustrCompacted)->buffer[(*pustrCompacted)->length] = 0;
103 uPathWidth = pfnCalcWidth( *pustrCompacted );
104 }
105
106 if ( ustrPath )
107 rtl_uString_release( ustrPath );
108
109 if ( ustrFile )
110 rtl_uString_release( ustrFile );
111
112 return error;
113}
114
115
116/* vim:set shiftwidth=4 softtabstop=4 expandtab: */