1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | #include <osl/file.h> |
21 | #include <rtl/ustring.h> |
22 | |
23 | static sal_uInt32 SAL_CALL osl_defCalcTextWidth( rtl_uString *ustrText ) |
24 | { |
25 | return ustrText ? ustrText->length : 0; |
| 4 | | Assuming 'ustrText' is null | |
|
| |
26 | } |
27 | |
28 | |
29 | oslFileError 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 ) |
| |
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 ) |
| |
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 ); |
55 | uFileWidth = pfnCalcWidth( ustrFile ); |
| 3 | | Calling 'osl_defCalcTextWidth' | |
|
| 6 | | Returning from 'osl_defCalcTextWidth' | |
|
56 | |
57 | |
58 | |
59 | while ( uPathWidth + uFileWidth > uMaxWidth ) |
| 7 | | Loop condition is false. Execution continues on line 77 | |
|
60 | { |
61 | if ( ustrPath->length > 3 ) |
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 | |
76 | |
77 | while ( uPathWidth + uFileWidth > uMaxWidth ) |
| 8 | | Loop condition is true. Entering loop body | |
|
78 | { |
79 | if ( ustrFile->length > 4 ) |
| 9 | | Access to field 'length' results in a dereference of a null pointer (loaded from variable 'ustrFile') |
|
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 | |
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 | |