Kaydet (Commit) cbe3b2fe authored tarafından Matteo Casalin's avatar Matteo Casalin Kaydeden (comit) Stephan Bergmann

Avoid conversion warning in O[U]String[Buffer] constructors

Signed-off-by: Stephan Bergmann <sbergman@redhat.com>, modifying the patch to
carefully keep the undefined behavior in the already existing additions that may
potentially overflow, instead of making the static_cast<sal_Int32> introduction
look like end - pData->buffer will be guaranteed to fit into sal_Int32 (which it
is not).

Change-Id: Id2fb64dc4585dae34257be6968a8905254a3b42d
üst 1f832584
...@@ -211,7 +211,7 @@ public: ...@@ -211,7 +211,7 @@ public:
pData = rtl_string_alloc( nCapacity ); pData = rtl_string_alloc( nCapacity );
char* end = c.addData( pData->buffer ); char* end = c.addData( pData->buffer );
*end = '\0'; *end = '\0';
pData->length = end - pData->buffer; pData->length = l;
} }
#endif #endif
...@@ -486,13 +486,14 @@ public: ...@@ -486,13 +486,14 @@ public:
template< typename T1, typename T2 > template< typename T1, typename T2 >
OStringBuffer& append( const OStringConcat< T1, T2 >& c ) OStringBuffer& append( const OStringConcat< T1, T2 >& c )
{ {
const int l = c.length(); sal_Int32 l = c.length();
if( l == 0 ) if( l == 0 )
return *this; return *this;
rtl_stringbuffer_ensureCapacity( &pData, &nCapacity, pData->length + l ); l += pData->length;
rtl_stringbuffer_ensureCapacity( &pData, &nCapacity, l );
char* end = c.addData( pData->buffer + pData->length ); char* end = c.addData( pData->buffer + pData->length );
*end = '\0'; *end = '\0';
pData->length = end - pData->buffer; pData->length = l;
return *this; return *this;
} }
#endif #endif
......
...@@ -244,7 +244,7 @@ public: ...@@ -244,7 +244,7 @@ public:
if (l != 0) if (l != 0)
{ {
char* end = c.addData( pData->buffer ); char* end = c.addData( pData->buffer );
pData->length = end - pData->buffer; pData->length = l;
*end = '\0'; *end = '\0';
} }
} }
...@@ -305,13 +305,14 @@ public: ...@@ -305,13 +305,14 @@ public:
template< typename T1, typename T2 > template< typename T1, typename T2 >
OString& operator+=( const OStringConcat< T1, T2 >& c ) OString& operator+=( const OStringConcat< T1, T2 >& c )
{ {
const int l = c.length(); sal_Int32 l = c.length();
if( l == 0 ) if( l == 0 )
return *this; return *this;
rtl_string_ensureCapacity( &pData, pData->length + l ); l += pData->length;
rtl_string_ensureCapacity( &pData, l );
char* end = c.addData( pData->buffer + pData->length ); char* end = c.addData( pData->buffer + pData->length );
*end = '\0'; *end = '\0';
pData->length = end - pData->buffer; pData->length = l;
return *this; return *this;
} }
#endif #endif
......
...@@ -181,7 +181,7 @@ public: ...@@ -181,7 +181,7 @@ public:
pData = rtl_uString_alloc( nCapacity ); pData = rtl_uString_alloc( nCapacity );
sal_Unicode* end = c.addData( pData->buffer ); sal_Unicode* end = c.addData( pData->buffer );
*end = '\0'; *end = '\0';
pData->length = end - pData->buffer; pData->length = l;
// TODO realloc in case pData->>length is noticeably smaller than l ? // TODO realloc in case pData->>length is noticeably smaller than l ?
} }
#endif #endif
...@@ -484,13 +484,14 @@ public: ...@@ -484,13 +484,14 @@ public:
template< typename T1, typename T2 > template< typename T1, typename T2 >
OUStringBuffer& append( const OUStringConcat< T1, T2 >& c ) OUStringBuffer& append( const OUStringConcat< T1, T2 >& c )
{ {
const int l = c.length(); sal_Int32 l = c.length();
if( l == 0 ) if( l == 0 )
return *this; return *this;
rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, pData->length + l ); l += pData->length;
rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, l );
sal_Unicode* end = c.addData( pData->buffer + pData->length ); sal_Unicode* end = c.addData( pData->buffer + pData->length );
*end = '\0'; *end = '\0';
pData->length = end - pData->buffer; pData->length = l;
return *this; return *this;
} }
#endif #endif
......
...@@ -349,7 +349,7 @@ public: ...@@ -349,7 +349,7 @@ public:
if (l != 0) if (l != 0)
{ {
sal_Unicode* end = c.addData( pData->buffer ); sal_Unicode* end = c.addData( pData->buffer );
pData->length = end - pData->buffer; pData->length = l;
*end = '\0'; *end = '\0';
// TODO realloc in case pData->length is noticeably smaller than l? // TODO realloc in case pData->length is noticeably smaller than l?
} }
...@@ -445,13 +445,14 @@ public: ...@@ -445,13 +445,14 @@ public:
template< typename T1, typename T2 > template< typename T1, typename T2 >
OUString& operator+=( const OUStringConcat< T1, T2 >& c ) OUString& operator+=( const OUStringConcat< T1, T2 >& c )
{ {
const int l = c.length(); sal_Int32 l = c.length();
if( l == 0 ) if( l == 0 )
return *this; return *this;
rtl_uString_ensureCapacity( &pData, pData->length + l ); l += pData->length;
rtl_uString_ensureCapacity( &pData, l );
sal_Unicode* end = c.addData( pData->buffer + pData->length ); sal_Unicode* end = c.addData( pData->buffer + pData->length );
*end = '\0'; *end = '\0';
pData->length = end - pData->buffer; pData->length = l;
return *this; return *this;
} }
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment