Bug Summary

File:sal/rtl/source/ustring.cxx
Location:line 1009, column 9
Description:Access to field 'length' results in a dereference of a null pointer (loaded from variable 'string')

Annotated Source Code

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 *
8 * OpenOffice.org - a multi-platform office productivity suite
9 *
10 * This file is part of OpenOffice.org.
11 *
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
15 *
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
21 *
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
26 *
27 ************************************************************************/
28
29#include "sal/config.h"
30
31#if defined(_MSC_VER) && (_MSC_VER >= 1400)
32#pragma warning(disable:4738) // storing 32-bit float result in memory, possible loss of performance
33#endif
34
35#include <cassert>
36#include <cstdlib>
37
38#include <rtl/memory.h>
39#include <osl/diagnose.h>
40#include <osl/interlck.h>
41#include <rtl/alloc.h>
42#include <osl/mutex.h>
43#include <osl/doublecheckedlocking.h>
44#include <rtl/tencinfo.h>
45
46#include <string.h>
47#include <sal/alloca.h>
48#include <sal/log.hxx>
49
50#include "hash.hxx"
51#include "strimp.hxx"
52#include "surrogates.hxx"
53#include <rtl/ustring.h>
54
55#include "rtl/math.h"
56#include "rtl/tencinfo.h"
57
58/* ======================================================================= */
59
60/* static data to be referenced by all empty strings
61 * the refCount is predefined to 1 and must never become 0 !
62 */
63static rtl_uString const aImplEmpty_rtl_uString =
64{
65 (sal_Int32) (SAL_STRING_INTERN_FLAG0x80000000|SAL_STRING_STATIC_FLAG0x40000000|1), /*sal_Int32 refCount; */
66 0, /*sal_Int32 length; */
67 { 0 } /*sal_Unicode buffer[1];*/
68};
69
70/* ======================================================================= */
71
72#define IMPL_RTL_STRCODEsal_Unicode sal_Unicode
73#define IMPL_RTL_USTRCODE( c )(c) (c)
74#define IMPL_RTL_STRNAME( n )rtl_ustr_n rtl_ustr_ ## n
75
76#define IMPL_RTL_STRINGNAME( n )rtl_uString_n rtl_uString_ ## n
77#define IMPL_RTL_STRINGDATArtl_uString rtl_uString
78#define IMPL_RTL_EMPTYSTRINGaImplEmpty_rtl_uString aImplEmpty_rtl_uString
79#define IMPL_RTL_INTERN
80static void internRelease (rtl_uString *pThis);
81
82/* ======================================================================= */
83
84/* Include String/UString template code */
85
86#include "strtmpl.cxx"
87
88sal_Int32 rtl_ustr_indexOfAscii_WithLength(
89 sal_Unicode const * str, sal_Int32 len,
90 char const * subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()throw ()
91{
92 if (subLen > 0 && subLen <= len) {
93 sal_Int32 i;
94 for (i = 0; i <= len - subLen; ++i) {
95 if (rtl_ustr_asciil_reverseEquals_WithLength(
96 str + i, subStr, subLen))
97 {
98 return i;
99 }
100 }
101 }
102 return -1;
103}
104
105sal_Int32 rtl_ustr_lastIndexOfAscii_WithLength(
106 sal_Unicode const * str, sal_Int32 len,
107 char const * subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()throw ()
108{
109 if (subLen > 0 && subLen <= len) {
110 sal_Int32 i;
111 for (i = len - subLen; i >= 0; --i) {
112 if (rtl_ustr_asciil_reverseEquals_WithLength(
113 str + i, subStr, subLen))
114 {
115 return i;
116 }
117 }
118 }
119 return -1;
120}
121
122sal_Int32 SAL_CALL rtl_ustr_valueOfFloat(sal_Unicode * pStr, float f)
123 SAL_THROW_EXTERN_C()throw ()
124{
125 rtl_uString * pResult = NULL__null;
126 sal_Int32 nLen;
127 rtl_math_doubleToUString(
128 &pResult, 0, 0, f, rtl_math_StringFormat_G,
129 RTL_USTR_MAX_VALUEOFFLOAT15 - RTL_CONSTASCII_LENGTH("-x.E-xxx")((sal_Int32)((sizeof ("-x.E-xxx") / sizeof (("-x.E-xxx")[0]))
-1))
, '.', 0,
130 0, sal_True((sal_Bool)1));
131 nLen = pResult->length;
132 OSL_ASSERT(nLen < RTL_USTR_MAX_VALUEOFFLOAT)do { if (true && (!(nLen < 15))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
":" "132" ": "), "OSL_ASSERT: %s", "nLen < RTL_USTR_MAX_VALUEOFFLOAT"
); } } while (false)
;
133 memcpy(pStr, pResult->buffer, (nLen + 1) * sizeof(sal_Unicode));
134 rtl_uString_release(pResult);
135 return nLen;
136}
137
138sal_Int32 SAL_CALL rtl_ustr_valueOfDouble(sal_Unicode * pStr, double d)
139 SAL_THROW_EXTERN_C()throw ()
140{
141 rtl_uString * pResult = NULL__null;
142 sal_Int32 nLen;
143 rtl_math_doubleToUString(
144 &pResult, 0, 0, d, rtl_math_StringFormat_G,
145 RTL_USTR_MAX_VALUEOFDOUBLE25 - RTL_CONSTASCII_LENGTH("-x.E-xxx")((sal_Int32)((sizeof ("-x.E-xxx") / sizeof (("-x.E-xxx")[0]))
-1))
, '.', 0,
146 0, sal_True((sal_Bool)1));
147 nLen = pResult->length;
148 OSL_ASSERT(nLen < RTL_USTR_MAX_VALUEOFDOUBLE)do { if (true && (!(nLen < 25))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
":" "148" ": "), "OSL_ASSERT: %s", "nLen < RTL_USTR_MAX_VALUEOFDOUBLE"
); } } while (false)
;
149 memcpy(pStr, pResult->buffer, (nLen + 1) * sizeof(sal_Unicode));
150 rtl_uString_release(pResult);
151 return nLen;
152}
153
154float SAL_CALL rtl_ustr_toFloat(sal_Unicode const * pStr) SAL_THROW_EXTERN_C()throw ()
155{
156 return (float) rtl_math_uStringToDouble(pStr,
157 pStr + rtl_ustr_getLength(pStr),
158 '.', 0, 0, 0);
159}
160
161double SAL_CALL rtl_ustr_toDouble(sal_Unicode const * pStr) SAL_THROW_EXTERN_C()throw ()
162{
163 return rtl_math_uStringToDouble(pStr, pStr + rtl_ustr_getLength(pStr), '.',
164 0, 0, 0);
165}
166
167/* ======================================================================= */
168
169sal_Int32 SAL_CALL rtl_ustr_ascii_compare( const sal_Unicode* pStr1,
170 const sal_Char* pStr2 )
171 SAL_THROW_EXTERN_C()throw ()
172{
173 sal_Int32 nRet;
174 while ( ((nRet = ((sal_Int32)(*pStr1))-
175 ((sal_Int32)((unsigned char)(*pStr2)))) == 0) &&
176 *pStr2 )
177 {
178 /* Check ASCII range */
179 SAL_WARN_IF( ((unsigned char)*pStr2) > 127, "rtl.string",do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compare - Found char > 127") ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"180" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compare - Found char > 127"));
} else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_ascii_compare - Found char > 127"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"),
("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"180" ": "), sal_detail_stream); } } } while (false)
180 "rtl_ustr_ascii_compare - Found char > 127" )do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compare - Found char > 127") ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"180" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compare - Found char > 127"));
} else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_ascii_compare - Found char > 127"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"),
("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"180" ": "), sal_detail_stream); } } } while (false)
;
181 pStr1++;
182 pStr2++;
183 }
184
185 return nRet;
186}
187
188/* ----------------------------------------------------------------------- */
189
190sal_Int32 SAL_CALL rtl_ustr_ascii_compare_WithLength( const sal_Unicode* pStr1,
191 sal_Int32 nStr1Len,
192 const sal_Char* pStr2 )
193 SAL_THROW_EXTERN_C()throw ()
194{
195 sal_Int32 nRet = 0;
196 while( ((nRet = (nStr1Len ? (sal_Int32)(*pStr1) : 0)-
197 ((sal_Int32)((unsigned char)(*pStr2)))) == 0) &&
198 nStr1Len && *pStr2 )
199 {
200 /* Check ASCII range */
201 SAL_WARN_IF( ((unsigned char)*pStr2) > 127, "rtl.string",do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compare_WithLength - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"202" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compare_WithLength - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_ascii_compare_WithLength - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"202" ": "), sal_detail_stream); } } } while (false)
202 "rtl_ustr_ascii_compare_WithLength - Found char > 127" )do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compare_WithLength - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"202" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compare_WithLength - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_ascii_compare_WithLength - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"202" ": "), sal_detail_stream); } } } while (false)
;
203 pStr1++;
204 pStr2++;
205 nStr1Len--;
206 }
207
208 return nRet;
209}
210
211/* ----------------------------------------------------------------------- */
212
213sal_Int32 SAL_CALL rtl_ustr_ascii_shortenedCompare_WithLength( const sal_Unicode* pStr1,
214 sal_Int32 nStr1Len,
215 const sal_Char* pStr2,
216 sal_Int32 nShortenedLength )
217 SAL_THROW_EXTERN_C()throw ()
218{
219 const sal_Unicode* pStr1End = pStr1 + nStr1Len;
220 sal_Int32 nRet;
221 while ( (nShortenedLength > 0) &&
222 (pStr1 < pStr1End) && *pStr2 )
223 {
224 /* Check ASCII range */
225 SAL_WARN_IF( ((unsigned char)*pStr2) > 127, "rtl.string",do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_shortenedCompare_WithLength - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"226" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_shortenedCompare_WithLength - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_ascii_shortenedCompare_WithLength - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"226" ": "), sal_detail_stream); } } } while (false)
226 "rtl_ustr_ascii_shortenedCompare_WithLength - Found char > 127" )do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_shortenedCompare_WithLength - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"226" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_shortenedCompare_WithLength - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_ascii_shortenedCompare_WithLength - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"226" ": "), sal_detail_stream); } } } while (false)
;
227
228 nRet = ((sal_Int32)*pStr1)-
229 ((sal_Int32)(unsigned char)*pStr2);
230 if ( nRet != 0 )
231 return nRet;
232
233 nShortenedLength--;
234 pStr1++;
235 pStr2++;
236 }
237
238 if ( nShortenedLength <= 0 )
239 return 0;
240
241 if ( *pStr2 )
242 {
243 OSL_ENSURE( pStr1 == pStr1End, "pStr1 == pStr1End failed" )do { if (true && (!(pStr1 == pStr1End))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
":" "243" ": "), "%s", "pStr1 == pStr1End failed"); } } while
(false)
;
244 // first is a substring of the second string => less (negative value)
245 nRet = -1;
246 }
247 else
248 {
249 // greater or equal
250 nRet = pStr1End - pStr1;
251 }
252
253 return nRet;
254}
255
256/* ----------------------------------------------------------------------- */
257
258sal_Int32 SAL_CALL rtl_ustr_asciil_reverseCompare_WithLength( const sal_Unicode* pStr1,
259 sal_Int32 nStr1Len,
260 const sal_Char* pStr2,
261 sal_Int32 nStr2Len )
262 SAL_THROW_EXTERN_C()throw ()
263{
264 const sal_Unicode* pStr1Run = pStr1+nStr1Len;
265 const sal_Char* pStr2Run = pStr2+nStr2Len;
266 sal_Int32 nRet;
267 while ( (pStr1 < pStr1Run) && (pStr2 < pStr2Run) )
268 {
269 /* Check ASCII range */
270 SAL_WARN_IF( ((unsigned char)*pStr2) > 127, "rtl.string",do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_asciil_reverseCompare_WithLength - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"271" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_asciil_reverseCompare_WithLength - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_asciil_reverseCompare_WithLength - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"271" ": "), sal_detail_stream); } } } while (false)
271 "rtl_ustr_asciil_reverseCompare_WithLength - Found char > 127" )do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_asciil_reverseCompare_WithLength - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"271" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_asciil_reverseCompare_WithLength - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_asciil_reverseCompare_WithLength - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"271" ": "), sal_detail_stream); } } } while (false)
;
272 pStr1Run--;
273 pStr2Run--;
274 nRet = ((sal_Int32)*pStr1Run)-((sal_Int32)*pStr2Run);
275 if ( nRet )
276 return nRet;
277 }
278
279 return nStr1Len - nStr2Len;
280}
281
282/* ----------------------------------------------------------------------- */
283
284sal_Bool SAL_CALL rtl_ustr_asciil_reverseEquals_WithLength( const sal_Unicode* pStr1,
285 const sal_Char* pStr2,
286 sal_Int32 nStrLen )
287 SAL_THROW_EXTERN_C()throw ()
288{
289 const sal_Unicode* pStr1Run = pStr1+nStrLen;
290 const sal_Char* pStr2Run = pStr2+nStrLen;
291 while ( pStr1 < pStr1Run )
292 {
293 /* Check ASCII range */
294 SAL_WARN_IF( ((unsigned char)*pStr2) > 127, "rtl.string",do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_asciil_reverseEquals_WithLength - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"295" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_asciil_reverseEquals_WithLength - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_asciil_reverseEquals_WithLength - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"295" ": "), sal_detail_stream); } } } while (false)
295 "rtl_ustr_asciil_reverseEquals_WithLength - Found char > 127" )do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_asciil_reverseEquals_WithLength - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"295" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_asciil_reverseEquals_WithLength - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_asciil_reverseEquals_WithLength - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"295" ": "), sal_detail_stream); } } } while (false)
;
296 pStr1Run--;
297 pStr2Run--;
298 if( *pStr1Run != (sal_Unicode)*pStr2Run )
299 return sal_False((sal_Bool)0);
300 }
301
302 return sal_True((sal_Bool)1);
303}
304
305/* ----------------------------------------------------------------------- */
306
307sal_Int32 SAL_CALL rtl_ustr_ascii_compareIgnoreAsciiCase( const sal_Unicode* pStr1,
308 const sal_Char* pStr2 )
309 SAL_THROW_EXTERN_C()throw ()
310{
311 sal_Int32 nRet;
312 sal_Int32 c1;
313 sal_Int32 c2;
314 do
315 {
316 /* Check ASCII range */
317 SAL_WARN_IF( ((unsigned char)*pStr2) > 127, "rtl.string",do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compareIgnoreAsciiCase - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"318" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compareIgnoreAsciiCase - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_ascii_compareIgnoreAsciiCase - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"318" ": "), sal_detail_stream); } } } while (false)
318 "rtl_ustr_ascii_compareIgnoreAsciiCase - Found char > 127" )do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compareIgnoreAsciiCase - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"318" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compareIgnoreAsciiCase - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_ascii_compareIgnoreAsciiCase - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"318" ": "), sal_detail_stream); } } } while (false)
;
319 /* If character between 'A' and 'Z', than convert it to lowercase */
320 c1 = (sal_Int32)*pStr1;
321 c2 = (sal_Int32)((unsigned char)*pStr2);
322 if ( (c1 >= 65) && (c1 <= 90) )
323 c1 += 32;
324 if ( (c2 >= 65) && (c2 <= 90) )
325 c2 += 32;
326 nRet = c1-c2;
327 if ( nRet != 0 )
328 return nRet;
329
330 pStr1++;
331 pStr2++;
332 }
333 while ( c2 );
334
335 return 0;
336}
337
338/* ----------------------------------------------------------------------- */
339
340sal_Int32 SAL_CALL rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( const sal_Unicode* pStr1,
341 sal_Int32 nStr1Len,
342 const sal_Char* pStr2 )
343 SAL_THROW_EXTERN_C()throw ()
344{
345 sal_Int32 nRet;
346 sal_Int32 c1;
347 sal_Int32 c2;
348 do
349 {
350 /* Check ASCII range */
351 SAL_WARN_IF( ((unsigned char)*pStr2) > 127, "rtl.string",do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"352" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"352" ": "), sal_detail_stream); } } } while (false)
352 "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength - Found char > 127" )do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"352" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"352" ": "), sal_detail_stream); } } } while (false)
;
353 if ( !nStr1Len )
354 return *pStr2 == '\0' ? 0 : -1;
355
356 /* If character between 'A' and 'Z', than convert it to lowercase */
357 c1 = (sal_Int32)*pStr1;
358 c2 = (sal_Int32)((unsigned char)*pStr2);
359 if ( (c1 >= 65) && (c1 <= 90) )
360 c1 += 32;
361 if ( (c2 >= 65) && (c2 <= 90) )
362 c2 += 32;
363 nRet = c1-c2;
364 if ( nRet != 0 )
365 return nRet;
366
367 pStr1++;
368 pStr2++;
369 nStr1Len--;
370 }
371 while( c2 );
372
373 return 0;
374}
375
376sal_Int32 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
377 sal_Unicode const * first, sal_Int32 firstLen,
378 char const * second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()throw ()
379{
380 sal_Int32 i;
381 sal_Int32 len = firstLen < secondLen ? firstLen : secondLen;
382 for (i = 0; i < len; ++i) {
383 /* Check ASCII range */
384 SAL_WARN_IF( ((unsigned char)*second) > 127, "rtl.string",do { if (true && (((unsigned char)*second) > 127))
{ if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"385" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"385" ": "), sal_detail_stream); } } } while (false)
385 "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths - Found char > 127" )do { if (true && (((unsigned char)*second) > 127))
{ if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"385" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"385" ": "), sal_detail_stream); } } } while (false)
;
386 sal_Int32 c1 = *first++;
387 sal_Int32 c2 = (unsigned char) *second++;
388 sal_Int32 d;
389 if (c1 >= 65 && c1 <= 90) {
390 c1 += 32;
391 }
392 if (c2 >= 65 && c2 <= 90) {
393 c2 += 32;
394 }
395 d = c1 - c2;
396 if (d != 0) {
397 return d;
398 }
399 }
400 return firstLen - secondLen;
401}
402
403/* ----------------------------------------------------------------------- */
404
405sal_Int32 SAL_CALL rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( const sal_Unicode* pStr1,
406 sal_Int32 nStr1Len,
407 const sal_Char* pStr2,
408 sal_Int32 nShortenedLength )
409 SAL_THROW_EXTERN_C()throw ()
410{
411 const sal_Unicode* pStr1End = pStr1 + nStr1Len;
412 sal_Int32 nRet;
413 sal_Int32 c1;
414 sal_Int32 c2;
415 while ( (nShortenedLength > 0) &&
416 (pStr1 < pStr1End) && *pStr2 )
417 {
418 /* Check ASCII range */
419 SAL_WARN_IF( ((unsigned char)*pStr2) > 127, "rtl.string",do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"420" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"420" ": "), sal_detail_stream); } } } while (false)
420 "rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength - Found char > 127" )do { if (true && (((unsigned char)*pStr2) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength - Found char > 127"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"420" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength - Found char > 127"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength - Found char > 127"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"420" ": "), sal_detail_stream); } } } while (false)
;
421
422 /* If character between 'A' and 'Z', than convert it to lowercase */
423 c1 = (sal_Int32)*pStr1;
424 c2 = (sal_Int32)((unsigned char)*pStr2);
425 if ( (c1 >= 65) && (c1 <= 90) )
426 c1 += 32;
427 if ( (c2 >= 65) && (c2 <= 90) )
428 c2 += 32;
429 nRet = c1-c2;
430 if ( nRet != 0 )
431 return nRet;
432
433 nShortenedLength--;
434 pStr1++;
435 pStr2++;
436 }
437
438 if ( nShortenedLength <= 0 )
439 return 0;
440
441 if ( *pStr2 )
442 {
443 OSL_ENSURE( pStr1 == pStr1End, "pStr1 == pStr1End failed" )do { if (true && (!(pStr1 == pStr1End))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
":" "443" ": "), "%s", "pStr1 == pStr1End failed"); } } while
(false)
;
444 // first is a substring of the second string => less (negative value)
445 nRet = -1;
446 }
447 else
448 {
449 // greater or equal
450 nRet = pStr1End - pStr1;
451 }
452
453 return nRet;
454}
455
456/* ----------------------------------------------------------------------- */
457
458void SAL_CALL rtl_uString_newFromAscii( rtl_uString** ppThis,
459 const sal_Char* pCharStr )
460 SAL_THROW_EXTERN_C()throw ()
461{
462 sal_Int32 nLen;
463
464 if ( pCharStr )
465 {
466 const sal_Char* pTempStr = pCharStr;
467 while( *pTempStr )
468 pTempStr++;
469 nLen = pTempStr-pCharStr;
470 }
471 else
472 nLen = 0;
473
474 if ( !nLen )
475 {
476 IMPL_RTL_STRINGNAME( new )rtl_uString_new( ppThis );
477 return;
478 }
479
480 if ( *ppThis )
481 IMPL_RTL_STRINGNAME( release )rtl_uString_release( *ppThis );
482
483 *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )rtl_uString_ImplAlloc( nLen );
484 OSL_ASSERT(*ppThis != NULL)do { if (true && (!(*ppThis != __null))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
":" "484" ": "), "OSL_ASSERT: %s", "*ppThis != NULL"); } } while
(false)
;
485 if ( (*ppThis) )
486 {
487 IMPL_RTL_STRCODEsal_Unicode* pBuffer = (*ppThis)->buffer;
488 do
489 {
490 /* Check ASCII range */
491 SAL_WARN_IF( ((unsigned char)*pCharStr) > 127, "rtl.string",do { if (true && (((unsigned char)*pCharStr) > 127
)) { if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_uString_newFromAscii - Found char > 127")
== 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"492" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_uString_newFromAscii - Found char > 127")
); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_uString_newFromAscii - Found char > 127"; ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"492" ": "), sal_detail_stream); } } } while (false)
492 "rtl_uString_newFromAscii - Found char > 127" )do { if (true && (((unsigned char)*pCharStr) > 127
)) { if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_uString_newFromAscii - Found char > 127")
== 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"492" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_uString_newFromAscii - Found char > 127")
); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_uString_newFromAscii - Found char > 127"; ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"492" ": "), sal_detail_stream); } } } while (false)
;
493
494 *pBuffer = *pCharStr;
495 pBuffer++;
496 pCharStr++;
497 }
498 while ( *pCharStr );
499 }
500
501 RTL_LOG_STRING_NEW( *ppThis );
502}
503
504void SAL_CALL rtl_uString_newFromCodePoints(
505 rtl_uString ** newString, sal_uInt32 const * codePoints,
506 sal_Int32 codePointCount) SAL_THROW_EXTERN_C()throw ()
507{
508 sal_Int32 n;
509 sal_Int32 i;
510 sal_Unicode * p;
511 OSL_ASSERT(do { if (true && (!(newString != __null && (codePoints
!= __null || codePointCount == 0) && codePointCount >=
0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"514" ": "), "OSL_ASSERT: %s", "newString != NULL && (codePoints != NULL || codePointCount == 0) && codePointCount >= 0"
); } } while (false)
512 newString != NULL &&do { if (true && (!(newString != __null && (codePoints
!= __null || codePointCount == 0) && codePointCount >=
0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"514" ": "), "OSL_ASSERT: %s", "newString != NULL && (codePoints != NULL || codePointCount == 0) && codePointCount >= 0"
); } } while (false)
513 (codePoints != NULL || codePointCount == 0) &&do { if (true && (!(newString != __null && (codePoints
!= __null || codePointCount == 0) && codePointCount >=
0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"514" ": "), "OSL_ASSERT: %s", "newString != NULL && (codePoints != NULL || codePointCount == 0) && codePointCount >= 0"
); } } while (false)
514 codePointCount >= 0)do { if (true && (!(newString != __null && (codePoints
!= __null || codePointCount == 0) && codePointCount >=
0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"514" ": "), "OSL_ASSERT: %s", "newString != NULL && (codePoints != NULL || codePointCount == 0) && codePointCount >= 0"
); } } while (false)
;
515 if (codePointCount == 0) {
516 rtl_uString_new(newString);
517 return;
518 }
519 if (*newString != NULL__null) {
520 rtl_uString_release(*newString);
521 }
522 n = codePointCount;
523 for (i = 0; i < codePointCount; ++i) {
524 OSL_ASSERT(codePoints[i] <= 0x10FFFF)do { if (true && (!(codePoints[i] <= 0x10FFFF))) {
sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"524" ": "), "OSL_ASSERT: %s", "codePoints[i] <= 0x10FFFF"
); } } while (false)
;
525 if (codePoints[i] >= 0x10000) {
526 ++n;
527 }
528 }
529 /* Builds on the assumption that sal_Int32 uses 32 bit two's complement
530 representation with wrap around (the necessary number of UTF-16 code
531 units will be no larger than 2 * SAL_MAX_INT32, represented as
532 sal_Int32 -2): */
533 if (n < 0) {
534 *newString = NULL__null;
535 return;
536 }
537 *newString = rtl_uString_ImplAlloc(n);
538 if (*newString == NULL__null) {
539 return;
540 }
541 p = (*newString)->buffer;
542 for (i = 0; i < codePointCount; ++i) {
543 sal_uInt32 c = codePoints[i];
544 if (c < 0x10000) {
545 *p++ = (sal_Unicode) c;
546 } else {
547 c -= 0x10000;
548 *p++ = (sal_Unicode) ((c >> 10) | SAL_RTL_FIRST_HIGH_SURROGATE0xD800);
549 *p++ = (sal_Unicode) ((c & 0x3FF) | SAL_RTL_FIRST_LOW_SURROGATE0xDC00);
550 }
551 }
552 RTL_LOG_STRING_NEW( *newString );
553}
554
555/* ======================================================================= */
556
557static int rtl_ImplGetFastUTF8UnicodeLen( const sal_Char* pStr, sal_Int32 nLen )
558{
559 int n;
560 sal_uChar c;
561 const sal_Char* pEndStr;
562
563 n = 0;
564 pEndStr = pStr+nLen;
565 while ( pStr < pEndStr )
566 {
567 c = (sal_uChar)*pStr;
568
569 if ( !(c & 0x80) )
570 pStr++;
571 else if ( (c & 0xE0) == 0xC0 )
572 pStr += 2;
573 else if ( (c & 0xF0) == 0xE0 )
574 pStr += 3;
575 else if ( (c & 0xF8) == 0xF0 )
576 pStr += 4;
577 else if ( (c & 0xFC) == 0xF8 )
578 pStr += 5;
579 else if ( (c & 0xFE) == 0xFC )
580 pStr += 6;
581 else
582 pStr++;
583
584 n++;
585 }
586
587 return n;
588}
589
590/* ----------------------------------------------------------------------- */
591
592static void rtl_string2UString_status( rtl_uString** ppThis,
593 const sal_Char* pStr,
594 sal_Int32 nLen,
595 rtl_TextEncoding eTextEncoding,
596 sal_uInt32 nCvtFlags,
597 sal_uInt32 *pInfo )
598{
599 OSL_ENSURE(nLen == 0 || rtl_isOctetTextEncoding(eTextEncoding),do { if (true && (!(nLen == 0 || rtl_isOctetTextEncoding
(eTextEncoding)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
":" "600" ": "), "%s", "rtl_string2UString_status() - Wrong TextEncoding"
); } } while (false)
600 "rtl_string2UString_status() - Wrong TextEncoding" )do { if (true && (!(nLen == 0 || rtl_isOctetTextEncoding
(eTextEncoding)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
":" "600" ": "), "%s", "rtl_string2UString_status() - Wrong TextEncoding"
); } } while (false)
;
601
602 if ( !nLen )
603 {
604 rtl_uString_new( ppThis );
605 if (pInfo != NULL__null) {
606 *pInfo = 0;
607 }
608 }
609 else
610 {
611 if ( *ppThis )
612 IMPL_RTL_STRINGNAME( release )rtl_uString_release( *ppThis );
613
614 /* Optimization for US-ASCII */
615 if ( eTextEncoding == RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11)) )
616 {
617 IMPL_RTL_STRCODEsal_Unicode* pBuffer;
618 *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )rtl_uString_ImplAlloc( nLen );
619 if (*ppThis == NULL__null) {
620 if (pInfo != NULL__null) {
621 *pInfo = RTL_TEXTTOUNICODE_INFO_ERROR((sal_uInt32)0x0001) |
622 RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL((sal_uInt32)0x0004);
623 }
624 return;
625 }
626 pBuffer = (*ppThis)->buffer;
627 do
628 {
629 /* Check ASCII range */
630 SAL_WARN_IF( ((unsigned char)*pStr) > 127, "rtl.string",do { if (true && (((unsigned char)*pStr) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_string2UString_status() - Found char > 127 and RTL_TEXTENCODING_ASCII_US is specified"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"631" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_string2UString_status() - Found char > 127 and RTL_TEXTENCODING_ASCII_US is specified"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_string2UString_status() - Found char > 127 and RTL_TEXTENCODING_ASCII_US is specified"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"631" ": "), sal_detail_stream); } } } while (false)
631 "rtl_string2UString_status() - Found char > 127 and RTL_TEXTENCODING_ASCII_US is specified" )do { if (true && (((unsigned char)*pStr) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_string2UString_status() - Found char > 127 and RTL_TEXTENCODING_ASCII_US is specified"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"631" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_string2UString_status() - Found char > 127 and RTL_TEXTENCODING_ASCII_US is specified"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_string2UString_status() - Found char > 127 and RTL_TEXTENCODING_ASCII_US is specified"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"631" ": "), sal_detail_stream); } } } while (false)
;
632
633 *pBuffer = *pStr;
634 pBuffer++;
635 pStr++;
636 nLen--;
637 }
638 while ( nLen );
639 if (pInfo != NULL__null) {
640 *pInfo = 0;
641 }
642 }
643 else
644 {
645 rtl_uString* pTemp;
646 rtl_uString* pTemp2 = NULL__null;
647 rtl_TextToUnicodeConverter hConverter;
648 sal_uInt32 nInfo;
649 sal_Size nSrcBytes;
650 sal_Size nDestChars;
651 sal_Size nNewLen;
652
653 /* Optimization for UTF-8 - we try to calculate the exact length */
654 /* For all other encoding we try the maximum - and reallocate
655 the buffer if needed */
656 if ( eTextEncoding == RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)) )
657 {
658 nNewLen = rtl_ImplGetFastUTF8UnicodeLen( pStr, nLen );
659 /* Includes the string only ASCII, then we could copy
660 the buffer faster */
661 if ( nNewLen == (sal_Size)nLen )
662 {
663 IMPL_RTL_STRCODEsal_Unicode* pBuffer;
664 *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )rtl_uString_ImplAlloc( nLen );
665 if (*ppThis == NULL__null)
666 {
667 if (pInfo != NULL__null) {
668 *pInfo = RTL_TEXTTOUNICODE_INFO_ERROR((sal_uInt32)0x0001) |
669 RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL((sal_uInt32)0x0004);
670 }
671 return;
672 }
673 pBuffer = (*ppThis)->buffer;
674 do
675 {
676 /* Check ASCII range */
677 SAL_WARN_IF( ((unsigned char)*pStr) > 127, "rtl.string",do { if (true && (((unsigned char)*pStr) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_string2UString_status() - UTF8 test encoding is wrong"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"678" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_string2UString_status() - UTF8 test encoding is wrong"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_string2UString_status() - UTF8 test encoding is wrong"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"678" ": "), sal_detail_stream); } } } while (false)
678 "rtl_string2UString_status() - UTF8 test encoding is wrong" )do { if (true && (((unsigned char)*pStr) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_string2UString_status() - UTF8 test encoding is wrong"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"678" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_string2UString_status() - UTF8 test encoding is wrong"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_string2UString_status() - UTF8 test encoding is wrong"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"678" ": "), sal_detail_stream); } } } while (false)
;
679
680 *pBuffer = *pStr;
681 pBuffer++;
682 pStr++;
683 nLen--;
684 }
685 while ( nLen );
686 if (pInfo != NULL__null) {
687 *pInfo = 0;
688 }
689 RTL_LOG_STRING_NEW( *ppThis );
690 return;
691 }
692 }
693 else
694 nNewLen = nLen;
695
696 nCvtFlags |= RTL_TEXTTOUNICODE_FLAGS_FLUSH((sal_uInt32)0x8000);
697 hConverter = rtl_createTextToUnicodeConverter( eTextEncoding );
698
699 pTemp = IMPL_RTL_STRINGNAME( ImplAlloc )rtl_uString_ImplAlloc( nNewLen );
700 if (pTemp == NULL__null) {
701 if (pInfo != NULL__null) {
702 *pInfo = RTL_TEXTTOUNICODE_INFO_ERROR((sal_uInt32)0x0001) |
703 RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL((sal_uInt32)0x0004);
704 }
705 return;
706 }
707 nDestChars = rtl_convertTextToUnicode( hConverter, 0,
708 pStr, nLen,
709 pTemp->buffer, nNewLen,
710 nCvtFlags,
711 &nInfo, &nSrcBytes );
712
713 /* Buffer not big enough, try again with enough space */
714 /* Shouldn't be the case, but if we get textencoding which
715 could results in more unicode characters we have this
716 code here. Could be the case for apple encodings */
717 while ( nInfo & RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL((sal_uInt32)0x0004) )
718 {
719 rtl_freeMemory( pTemp );
720 nNewLen += 8;
721 pTemp = IMPL_RTL_STRINGNAME( ImplAlloc )rtl_uString_ImplAlloc( nNewLen );
722 if (pTemp == NULL__null) {
723 if (pInfo != NULL__null) {
724 *pInfo = RTL_TEXTTOUNICODE_INFO_ERROR((sal_uInt32)0x0001) |
725 RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL((sal_uInt32)0x0004);
726 }
727 return;
728 }
729 nDestChars = rtl_convertTextToUnicode( hConverter, 0,
730 pStr, nLen,
731 pTemp->buffer, nNewLen,
732 nCvtFlags,
733 &nInfo, &nSrcBytes );
734 }
735
736 if (pInfo)
737 *pInfo = nInfo;
738
739 /* Set the buffer to the correct size or if there is too
740 much overhead, reallocate to the correct size */
741 if ( nNewLen > nDestChars+8 )
742 {
743 pTemp2 = IMPL_RTL_STRINGNAME( ImplAlloc )rtl_uString_ImplAlloc( nDestChars );
744 }
745 if (pTemp2 != NULL__null)
746 {
747 rtl_str_ImplCopy(pTemp2->buffer, pTemp->buffer, nDestChars){ sal_Unicode* __mm_pDest = pTemp2->buffer; const sal_Unicode
* __mm_pSrc = pTemp->buffer; sal_Int32 __mm_nCount = nDestChars
; while ( __mm_nCount > 0 ) { *__mm_pDest = *__mm_pSrc; __mm_pDest
++; __mm_pSrc++; __mm_nCount--; } }
;
748 rtl_freeMemory(pTemp);
749 pTemp = pTemp2;
750 }
751 else
752 {
753 pTemp->length = nDestChars;
754 pTemp->buffer[nDestChars] = 0;
755 }
756
757 rtl_destroyTextToUnicodeConverter( hConverter );
758 *ppThis = pTemp;
759
760 /* Results the conversion in an empty buffer -
761 create an empty string */
762 if ( pTemp && !nDestChars )
763 rtl_uString_new( ppThis );
764 }
765 }
766 RTL_LOG_STRING_NEW( *ppThis );
767}
768
769void SAL_CALL rtl_string2UString( rtl_uString** ppThis,
770 const sal_Char* pStr,
771 sal_Int32 nLen,
772 rtl_TextEncoding eTextEncoding,
773 sal_uInt32 nCvtFlags ) SAL_THROW_EXTERN_C()throw ()
774{
775 rtl_string2UString_status( ppThis, pStr, nLen, eTextEncoding,
776 nCvtFlags, NULL__null );
777}
778
779/* ----------------------------------------------------------------------- */
780
781enum StrLifecycle {
782 CANNOT_RETURN,
783 CAN_RETURN = 1
784};
785
786static oslMutex
787getInternMutex()
788{
789 static oslMutex pPoolGuard = NULL__null;
790 if( !pPoolGuard )
791 {
792 oslMutex pGlobalGuard;
793 pGlobalGuard = *osl_getGlobalMutex();
794 osl_acquireMutex( pGlobalGuard );
795 if( !pPoolGuard )
796 {
797 oslMutex p = osl_createMutex();
798 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
799 pPoolGuard = p;
800 }
801 osl_releaseMutex( pGlobalGuard );
802 }
803 else
804 {
805 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
806 }
807
808 return pPoolGuard;
809}
810
811/* returns true if we found a dup in the pool */
812static void rtl_ustring_intern_internal( rtl_uString ** newStr,
813 rtl_uString * str,
814 StrLifecycle can_return )
815{
816 oslMutex pPoolMutex;
817
818 pPoolMutex = getInternMutex();
819
820 osl_acquireMutex( pPoolMutex );
821
822 *newStr = rtl_str_hash_intern (str, can_return);
823
824 osl_releaseMutex( pPoolMutex );
825
826 if( can_return && *newStr != str )
827 { /* we dupped, then found a match */
828 rtl_freeMemory( str );
829 }
830}
831
832void SAL_CALL rtl_uString_intern( rtl_uString ** newStr,
833 rtl_uString * str) SAL_THROW_EXTERN_C()throw ()
834{
835 if (SAL_STRING_IS_INTERN(str)((str)->refCount & 0x80000000))
836 {
837 IMPL_RTL_AQUIRE( str ){ if (!((str)->refCount & 0x40000000)) osl_incrementInterlockedCount
( &((str)->refCount) ); }
;
838 *newStr = str;
839 }
840 else
841 {
842 rtl_uString *pOrg = *newStr;
843 *newStr = NULL__null;
844 rtl_ustring_intern_internal( newStr, str, CANNOT_RETURN );
845 if (pOrg)
846 rtl_uString_release (pOrg);
847 }
848}
849
850static int rtl_canGuessUOutputLength( int len, rtl_TextEncoding eTextEncoding )
851{
852 // FIXME: Maybe we should use a bit flag in the higher bits of the
853 // eTextEncoding value itself to determine the encoding type. But if we
854 // do, be sure to mask the value in certain places that expect the values
855 // to be numbered serially from 0 and up. One such place is
856 // Impl_getTextEncodingData().
857
858 switch ( eTextEncoding )
859 {
860 // 1 to 1 (with no zero elements)
861 case RTL_TEXTENCODING_IBM_437(((rtl_TextEncoding) 3)):
862 case RTL_TEXTENCODING_IBM_850(((rtl_TextEncoding) 4)):
863 case RTL_TEXTENCODING_IBM_860(((rtl_TextEncoding) 5)):
864 case RTL_TEXTENCODING_IBM_861(((rtl_TextEncoding) 6)):
865 case RTL_TEXTENCODING_IBM_863(((rtl_TextEncoding) 7)):
866 case RTL_TEXTENCODING_IBM_865(((rtl_TextEncoding) 8)):
867 return len;
868 break;
869 }
870 return 0;
871}
872
873void SAL_CALL rtl_uString_internConvert( rtl_uString ** newStr,
874 const sal_Char * str,
875 sal_Int32 len,
876 rtl_TextEncoding eTextEncoding,
877 sal_uInt32 convertFlags,
878 sal_uInt32 * pInfo )
879 SAL_THROW_EXTERN_C()throw ()
880{
881 rtl_uString *scratch;
882
883 if (*newStr)
884 {
885 rtl_uString_release (*newStr);
886 *newStr = NULL__null;
887 }
888
889 if ( len < 256 )
890 { // try various optimisations
891 sal_Int32 ulen;
892 if ( len < 0 )
893 len = strlen( str );
894 if ( eTextEncoding == RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11)) )
895 {
896 int i;
897 rtl_uString *pScratch;
898 pScratch = static_cast< rtl_uString * >(
899 alloca(sizeof (rtl_uString) + len * sizeof (IMPL_RTL_STRCODE))__builtin_alloca (sizeof (rtl_uString) + len * sizeof (sal_Unicode
))
);
900 for (i = 0; i < len; i++)
901 {
902 /* Check ASCII range */
903 SAL_WARN_IF( ((unsigned char)str[i]) > 127, "rtl.string",do { if (true && (((unsigned char)str[i]) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustring_internConvert() - Found char > 127 and RTL_TEXTENCODING_ASCII_US is specified"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"904" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustring_internConvert() - Found char > 127 and RTL_TEXTENCODING_ASCII_US is specified"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustring_internConvert() - Found char > 127 and RTL_TEXTENCODING_ASCII_US is specified"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"904" ": "), sal_detail_stream); } } } while (false)
904 "rtl_ustring_internConvert() - Found char > 127 and RTL_TEXTENCODING_ASCII_US is specified" )do { if (true && (((unsigned char)str[i]) > 127)) {
if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "rtl_ustring_internConvert() - Found char > 127 and RTL_TEXTENCODING_ASCII_US is specified"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"904" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart
() << "rtl_ustring_internConvert() - Found char > 127 and RTL_TEXTENCODING_ASCII_US is specified"
)); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "rtl_ustring_internConvert() - Found char > 127 and RTL_TEXTENCODING_ASCII_US is specified"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string"
), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx" ":"
"904" ": "), sal_detail_stream); } } } while (false)
;
905 pScratch->buffer[i] = str[i];
906 }
907 pScratch->length = len;
908 rtl_ustring_intern_internal( newStr, pScratch, CANNOT_RETURN );
909 return;
910 }
911 else if ( (ulen = rtl_canGuessUOutputLength(len, eTextEncoding)) != 0 )
912 {
913 rtl_uString *pScratch;
914 rtl_TextToUnicodeConverter hConverter;
915 sal_Size nSrcBytes;
916 sal_uInt32 nInfo;
917
918 pScratch = static_cast< rtl_uString * >(
919 alloca(__builtin_alloca (sizeof (rtl_uString) + ulen * sizeof (sal_Unicode
))
920 sizeof (rtl_uString) + ulen * sizeof (IMPL_RTL_STRCODE))__builtin_alloca (sizeof (rtl_uString) + ulen * sizeof (sal_Unicode
))
);
921
922 hConverter = rtl_createTextToUnicodeConverter( eTextEncoding );
923 rtl_convertTextToUnicode(
924 hConverter, 0, str, len, pScratch->buffer, ulen, convertFlags, &nInfo, &nSrcBytes );
925 rtl_destroyTextToUnicodeConverter( hConverter );
926
927 if (pInfo)
928 *pInfo = nInfo;
929
930 pScratch->length = ulen;
931 rtl_ustring_intern_internal( newStr, pScratch, CANNOT_RETURN );
932 return;
933 }
934
935 /* FIXME: we want a nice UTF-8 / alloca shortcut here */
936 }
937
938 scratch = NULL__null;
939 rtl_string2UString_status( &scratch, str, len, eTextEncoding, convertFlags,
940 pInfo );
941 if (!scratch) {
942 return;
943 }
944 rtl_ustring_intern_internal( newStr, scratch, CAN_RETURN );
945}
946
947static void
948internRelease (rtl_uString *pThis)
949{
950 oslMutex pPoolMutex;
951
952 rtl_uString *pFree = NULL__null;
953 if ( SAL_STRING_REFCOUNT(((osl_decrementInterlockedCount( &(pThis->refCount) ))
& 0x3fffffff)
954 osl_decrementInterlockedCount( &(pThis->refCount) ) )((osl_decrementInterlockedCount( &(pThis->refCount) ))
& 0x3fffffff)
== 0)
955 {
956 pPoolMutex = getInternMutex();
957 osl_acquireMutex( pPoolMutex );
958
959 rtl_str_hash_remove (pThis);
960
961 /* May have been separately acquired */
962 if ( SAL_STRING_REFCOUNT(((osl_incrementInterlockedCount( &(pThis->refCount) ))
& 0x3fffffff)
963 osl_incrementInterlockedCount( &(pThis->refCount) ) )((osl_incrementInterlockedCount( &(pThis->refCount) ))
& 0x3fffffff)
== 1 )
964 {
965 /* we got the last ref */
966 pFree = pThis;
967 }
968 else /* very unusual */
969 {
970 internRelease (pThis);
971 }
972
973 osl_releaseMutex( pPoolMutex );
974 }
975 if (pFree)
976 rtl_freeMemory (pFree);
977}
978
979sal_uInt32 SAL_CALL rtl_uString_iterateCodePoints(
980 rtl_uString const * string, sal_Int32 * indexUtf16,
981 sal_Int32 incrementCodePoints)
982{
983 sal_Int32 n;
984 sal_Unicode cu;
985 sal_uInt32 cp;
986 OSL_ASSERT(string != NULL && indexUtf16 != NULL)do { if (true && (!(string != __null && indexUtf16
!= __null))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
":" "986" ": "), "OSL_ASSERT: %s", "string != NULL && indexUtf16 != NULL"
); } } while (false)
;
987 n = *indexUtf16;
988 OSL_ASSERT(n >= 0 && n <= string->length)do { if (true && (!(n >= 0 && n <= string
->length))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
":" "988" ": "), "OSL_ASSERT: %s", "n >= 0 && n <= string->length"
); } } while (false)
;
989 while (incrementCodePoints < 0) {
1
Loop condition is false. Execution continues on line 999
990 OSL_ASSERT(n > 0)do { if (true && (!(n > 0))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
":" "990" ": "), "OSL_ASSERT: %s", "n > 0"); } } while (false
)
;
991 cu = string->buffer[--n];
992 if (SAL_RTL_IS_LOW_SURROGATE(cu)((cu) >= 0xDC00 && (cu) <= 0xDFFF) && n != 0 &&
993 SAL_RTL_IS_HIGH_SURROGATE(string->buffer[n - 1])((string->buffer[n - 1]) >= 0xD800 && (string->
buffer[n - 1]) <= 0xDBFF)
)
994 {
995 --n;
996 }
997 ++incrementCodePoints;
998 }
999 OSL_ASSERT(n >= 0 && n < string->length)do { if (true && (!(n >= 0 && n < string
->length))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
":" "999" ": "), "OSL_ASSERT: %s", "n >= 0 && n < string->length"
); } } while (false)
;
1000 cu = string->buffer[n];
1001 if (SAL_RTL_IS_HIGH_SURROGATE(cu)((cu) >= 0xD800 && (cu) <= 0xDBFF) && string->length - n >= 2 &&
1002 SAL_RTL_IS_LOW_SURROGATE(string->buffer[n + 1])((string->buffer[n + 1]) >= 0xDC00 && (string->
buffer[n + 1]) <= 0xDFFF)
)
1003 {
1004 cp = SAL_RTL_COMBINE_SURROGATES(cu, string->buffer[n + 1])((((cu) - 0xD800) << 10) + ((string->buffer[n + 1]) -
0xDC00) + 0x10000)
;
1005 } else {
1006 cp = cu;
1007 }
1008 while (incrementCodePoints > 0) {
2
Loop condition is true. Entering loop body
1009 OSL_ASSERT(n < string->length)do { if (true && (!(n < string->length))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
":" "1009" ": "), "OSL_ASSERT: %s", "n < string->length"
); } } while (false)
;
3
Within the expansion of the macro 'OSL_ASSERT':
a
Access to field 'length' results in a dereference of a null pointer (loaded from variable 'string')
1010 cu = string->buffer[n++];
1011 if (SAL_RTL_IS_HIGH_SURROGATE(cu)((cu) >= 0xD800 && (cu) <= 0xDBFF) && n != string->length &&
1012 SAL_RTL_IS_LOW_SURROGATE(string->buffer[n])((string->buffer[n]) >= 0xDC00 && (string->buffer
[n]) <= 0xDFFF)
)
1013 {
1014 ++n;
1015 }
1016 --incrementCodePoints;
1017 }
1018 OSL_ASSERT(n >= 0 && n <= string->length)do { if (true && (!(n >= 0 && n <= string
->length))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
":" "1018" ": "), "OSL_ASSERT: %s", "n >= 0 && n <= string->length"
); } } while (false)
;
1019 *indexUtf16 = n;
1020 return cp;
1021}
1022
1023sal_Bool rtl_convertStringToUString(
1024 rtl_uString ** target, char const * source, sal_Int32 length,
1025 rtl_TextEncoding encoding, sal_uInt32 flags) SAL_THROW_EXTERN_C()throw ()
1026{
1027 sal_uInt32 info;
1028 rtl_string2UString_status(target, source, length, encoding, flags, &info);
1029 return (sal_Bool) ((info & RTL_TEXTTOUNICODE_INFO_ERROR((sal_uInt32)0x0001)) == 0);
1030}
1031
1032void rtl_uString_newReplaceFirst(
1033 rtl_uString ** newStr, rtl_uString * str, rtl_uString const * from,
1034 rtl_uString const * to, sal_Int32 * index) SAL_THROW_EXTERN_C()throw ()
1035{
1036 assert(str != 0)((str != 0) ? static_cast<void> (0) : __assert_fail ("str != 0"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1036
, __PRETTY_FUNCTION__))
;
1037 assert(index != 0)((index != 0) ? static_cast<void> (0) : __assert_fail (
"index != 0", "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
, 1037, __PRETTY_FUNCTION__))
;
1038 assert(*index >= 0 && *index <= str->length)((*index >= 0 && *index <= str->length) ? static_cast
<void> (0) : __assert_fail ("*index >= 0 && *index <= str->length"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1038
, __PRETTY_FUNCTION__))
;
1039 assert(from != 0)((from != 0) ? static_cast<void> (0) : __assert_fail ("from != 0"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1039
, __PRETTY_FUNCTION__))
;
1040 assert(to != 0)((to != 0) ? static_cast<void> (0) : __assert_fail ("to != 0"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1040
, __PRETTY_FUNCTION__))
;
1041 sal_Int32 i = rtl_ustr_indexOfStr_WithLength(
1042 str->buffer + *index, str->length - *index, from->buffer, from->length);
1043 if (i == -1) {
1044 rtl_uString_assign(newStr, str);
1045 } else {
1046 assert(i <= str->length - *index)((i <= str->length - *index) ? static_cast<void> (
0) : __assert_fail ("i <= str->length - *index", "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
, 1046, __PRETTY_FUNCTION__))
;
1047 i += *index;
1048 assert(from->length <= str->length)((from->length <= str->length) ? static_cast<void
> (0) : __assert_fail ("from->length <= str->length"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1048
, __PRETTY_FUNCTION__))
;
1049 if (str->length - from->length > SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF) - to->length) {
1050 std::abort();
1051 }
1052 sal_Int32 n = str->length - from->length + to->length;
1053 rtl_uString_acquire(str); // in case *newStr == str
1054 rtl_uString_new_WithLength(newStr, n);
1055 if (n != 0) {
1056 (*newStr)->length = n;
1057 assert(i >= 0 && i < str->length)((i >= 0 && i < str->length) ? static_cast<
void> (0) : __assert_fail ("i >= 0 && i < str->length"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1057
, __PRETTY_FUNCTION__))
;
1058 memcpy(
1059 (*newStr)->buffer, str->buffer, i * sizeof (sal_Unicode));
1060 memcpy(
1061 (*newStr)->buffer + i, to->buffer,
1062 to->length * sizeof (sal_Unicode));
1063 memcpy(
1064 (*newStr)->buffer + i + to->length,
1065 str->buffer + i + from->length,
1066 (str->length - i - from->length) * sizeof (sal_Unicode));
1067 }
1068 rtl_uString_release(str);
1069 }
1070 *index = i;
1071}
1072
1073void rtl_uString_newReplaceFirstAsciiL(
1074 rtl_uString ** newStr, rtl_uString * str, char const * from,
1075 sal_Int32 fromLength, rtl_uString const * to, sal_Int32 * index)
1076 SAL_THROW_EXTERN_C()throw ()
1077{
1078 assert(str != 0)((str != 0) ? static_cast<void> (0) : __assert_fail ("str != 0"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1078
, __PRETTY_FUNCTION__))
;
1079 assert(index != 0)((index != 0) ? static_cast<void> (0) : __assert_fail (
"index != 0", "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
, 1079, __PRETTY_FUNCTION__))
;
1080 assert(*index >= 0 && *index <= str->length)((*index >= 0 && *index <= str->length) ? static_cast
<void> (0) : __assert_fail ("*index >= 0 && *index <= str->length"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1080
, __PRETTY_FUNCTION__))
;
1081 assert(fromLength >= 0)((fromLength >= 0) ? static_cast<void> (0) : __assert_fail
("fromLength >= 0", "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
, 1081, __PRETTY_FUNCTION__))
;
1082 assert(to != 0)((to != 0) ? static_cast<void> (0) : __assert_fail ("to != 0"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1082
, __PRETTY_FUNCTION__))
;
1083 sal_Int32 i = rtl_ustr_indexOfAscii_WithLength(
1084 str->buffer + *index, str->length - *index, from, fromLength);
1085 if (i == -1) {
1086 rtl_uString_assign(newStr, str);
1087 } else {
1088 assert(i <= str->length - *index)((i <= str->length - *index) ? static_cast<void> (
0) : __assert_fail ("i <= str->length - *index", "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
, 1088, __PRETTY_FUNCTION__))
;
1089 i += *index;
1090 assert(fromLength <= str->length)((fromLength <= str->length) ? static_cast<void> (
0) : __assert_fail ("fromLength <= str->length", "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
, 1090, __PRETTY_FUNCTION__))
;
1091 if (str->length - fromLength > SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF) - to->length) {
1092 std::abort();
1093 }
1094 sal_Int32 n = str->length - fromLength + to->length;
1095 rtl_uString_acquire(str); // in case *newStr == str
1096 if (n != 0) {
1097 rtl_uString_new_WithLength(newStr, n);
1098 (*newStr)->length = n;
1099 assert(i >= 0 && i < str->length)((i >= 0 && i < str->length) ? static_cast<
void> (0) : __assert_fail ("i >= 0 && i < str->length"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1099
, __PRETTY_FUNCTION__))
;
1100 memcpy(
1101 (*newStr)->buffer, str->buffer, i * sizeof (sal_Unicode));
1102 memcpy(
1103 (*newStr)->buffer + i, to->buffer,
1104 to->length * sizeof (sal_Unicode));
1105 memcpy(
1106 (*newStr)->buffer + i + to->length,
1107 str->buffer + i + fromLength,
1108 (str->length - i - fromLength) * sizeof (sal_Unicode));
1109 }
1110 rtl_uString_release(str);
1111 }
1112 *index = i;
1113}
1114
1115void rtl_uString_newReplaceFirstAsciiLAsciiL(
1116 rtl_uString ** newStr, rtl_uString * str, char const * from,
1117 sal_Int32 fromLength, char const * to, sal_Int32 toLength,
1118 sal_Int32 * index) SAL_THROW_EXTERN_C()throw ()
1119{
1120 assert(str != 0)((str != 0) ? static_cast<void> (0) : __assert_fail ("str != 0"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1120
, __PRETTY_FUNCTION__))
;
1121 assert(index != 0)((index != 0) ? static_cast<void> (0) : __assert_fail (
"index != 0", "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
, 1121, __PRETTY_FUNCTION__))
;
1122 assert(*index >= 0 && *index <= str->length)((*index >= 0 && *index <= str->length) ? static_cast
<void> (0) : __assert_fail ("*index >= 0 && *index <= str->length"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1122
, __PRETTY_FUNCTION__))
;
1123 assert(fromLength >= 0)((fromLength >= 0) ? static_cast<void> (0) : __assert_fail
("fromLength >= 0", "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
, 1123, __PRETTY_FUNCTION__))
;
1124 assert(to != 0)((to != 0) ? static_cast<void> (0) : __assert_fail ("to != 0"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1124
, __PRETTY_FUNCTION__))
;
1125 assert(toLength >= 0)((toLength >= 0) ? static_cast<void> (0) : __assert_fail
("toLength >= 0", "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
, 1125, __PRETTY_FUNCTION__))
;
1126 sal_Int32 i = rtl_ustr_indexOfAscii_WithLength(
1127 str->buffer + *index, str->length - *index, from, fromLength);
1128 if (i == -1) {
1129 rtl_uString_assign(newStr, str);
1130 } else {
1131 assert(i <= str->length - *index)((i <= str->length - *index) ? static_cast<void> (
0) : __assert_fail ("i <= str->length - *index", "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
, 1131, __PRETTY_FUNCTION__))
;
1132 i += *index;
1133 assert(fromLength <= str->length)((fromLength <= str->length) ? static_cast<void> (
0) : __assert_fail ("fromLength <= str->length", "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
, 1133, __PRETTY_FUNCTION__))
;
1134 if (str->length - fromLength > SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF) - toLength) {
1135 std::abort();
1136 }
1137 sal_Int32 n = str->length - fromLength + toLength;
1138 rtl_uString_acquire(str); // in case *newStr == str
1139 if (n != 0) {
1140 rtl_uString_new_WithLength(newStr, n);
1141 (*newStr)->length = n;
1142 assert(i >= 0 && i < str->length)((i >= 0 && i < str->length) ? static_cast<
void> (0) : __assert_fail ("i >= 0 && i < str->length"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1142
, __PRETTY_FUNCTION__))
;
1143 memcpy(
1144 (*newStr)->buffer, str->buffer, i * sizeof (sal_Unicode));
1145 for (sal_Int32 j = 0; j != toLength; ++j) {
1146 assert(static_cast< unsigned char >(to[j]) <= 0x7F)((static_cast< unsigned char >(to[j]) <= 0x7F) ? static_cast
<void> (0) : __assert_fail ("static_cast< unsigned char >(to[j]) <= 0x7F"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1146
, __PRETTY_FUNCTION__))
;
1147 (*newStr)->buffer[i + j] = to[j];
1148 }
1149 memcpy(
1150 (*newStr)->buffer + i + toLength,
1151 str->buffer + i + fromLength,
1152 (str->length - i - fromLength) * sizeof (sal_Unicode));
1153 }
1154 rtl_uString_release(str);
1155 }
1156 *index = i;
1157}
1158
1159void rtl_uString_newReplaceAll(
1160 rtl_uString ** newStr, rtl_uString * str, rtl_uString const * from,
1161 rtl_uString const * to) SAL_THROW_EXTERN_C()throw ()
1162{
1163 assert(to != 0)((to != 0) ? static_cast<void> (0) : __assert_fail ("to != 0"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1163
, __PRETTY_FUNCTION__))
;
1164 rtl_uString_assign(newStr, str);
1165 for (sal_Int32 i = 0;; i += to->length) {
1166 rtl_uString_newReplaceFirst(newStr, *newStr, from, to, &i);
1167 if (i == -1) {
1168 break;
1169 }
1170 }
1171}
1172
1173void rtl_uString_newReplaceAllAsciiL(
1174 rtl_uString ** newStr, rtl_uString * str, char const * from,
1175 sal_Int32 fromLength, rtl_uString const * to) SAL_THROW_EXTERN_C()throw ()
1176{
1177 assert(to != 0)((to != 0) ? static_cast<void> (0) : __assert_fail ("to != 0"
, "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx", 1177
, __PRETTY_FUNCTION__))
;
1178 rtl_uString_assign(newStr, str);
1179 for (sal_Int32 i = 0;; i += to->length) {
1180 rtl_uString_newReplaceFirstAsciiL(
1181 newStr, *newStr, from, fromLength, to, &i);
1182 if (i == -1) {
1183 break;
1184 }
1185 }
1186}
1187
1188void rtl_uString_newReplaceAllAsciiLAsciiL(
1189 rtl_uString ** newStr, rtl_uString * str, char const * from,
1190 sal_Int32 fromLength, char const * to, sal_Int32 toLength)
1191 SAL_THROW_EXTERN_C()throw ()
1192{
1193 assert(toLength >= 0)((toLength >= 0) ? static_cast<void> (0) : __assert_fail
("toLength >= 0", "/usr/local/src/libreoffice/sal/rtl/source/ustring.cxx"
, 1193, __PRETTY_FUNCTION__))
;
1194 rtl_uString_assign(newStr, str);
1195 for (sal_Int32 i = 0;; i += toLength) {
1196 rtl_uString_newReplaceFirstAsciiLAsciiL(
1197 newStr, *newStr, from, fromLength, to, toLength, &i);
1198 if (i == -1) {
1199 break;
1200 }
1201 }
1202}
1203
1204/* vim:set shiftwidth=4 softtabstop=4 expandtab: */