summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMatteo Casalin <matteo.casalin@yahoo.com>2015-06-20 15:37:35 +0200
committerStephan Bergmann <sbergman@redhat.com>2015-06-23 12:33:36 +0200
commitcbe3b2fe0b9d745e22a2bf436ce55141b15f9502 (patch)
tree899722f2db90c470102608485f89b0ef71424ef7 /include
parent1f832584f7cfa78d5b9c2de66d5133635f587ab0 (diff)
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
Diffstat (limited to 'include')
-rw-r--r--include/rtl/strbuf.hxx9
-rw-r--r--include/rtl/string.hxx9
-rw-r--r--include/rtl/ustrbuf.hxx9
-rw-r--r--include/rtl/ustring.hxx9
4 files changed, 20 insertions, 16 deletions
diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index 52d29cabead3..81773b48a28a 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -211,7 +211,7 @@ public:
pData = rtl_string_alloc( nCapacity );
char* end = c.addData( pData->buffer );
*end = '\0';
- pData->length = end - pData->buffer;
+ pData->length = l;
}
#endif
@@ -486,13 +486,14 @@ public:
template< typename T1, typename T2 >
OStringBuffer& append( const OStringConcat< T1, T2 >& c )
{
- const int l = c.length();
+ sal_Int32 l = c.length();
if( l == 0 )
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 );
*end = '\0';
- pData->length = end - pData->buffer;
+ pData->length = l;
return *this;
}
#endif
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 94dad50bc3b4..56cbf932cea1 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -244,7 +244,7 @@ public:
if (l != 0)
{
char* end = c.addData( pData->buffer );
- pData->length = end - pData->buffer;
+ pData->length = l;
*end = '\0';
}
}
@@ -305,13 +305,14 @@ public:
template< typename T1, typename T2 >
OString& operator+=( const OStringConcat< T1, T2 >& c )
{
- const int l = c.length();
+ sal_Int32 l = c.length();
if( l == 0 )
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 );
*end = '\0';
- pData->length = end - pData->buffer;
+ pData->length = l;
return *this;
}
#endif
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index abb85a087ce2..04ac8a6c00f4 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -181,7 +181,7 @@ public:
pData = rtl_uString_alloc( nCapacity );
sal_Unicode* end = c.addData( pData->buffer );
*end = '\0';
- pData->length = end - pData->buffer;
+ pData->length = l;
// TODO realloc in case pData->>length is noticeably smaller than l ?
}
#endif
@@ -484,13 +484,14 @@ public:
template< typename T1, typename T2 >
OUStringBuffer& append( const OUStringConcat< T1, T2 >& c )
{
- const int l = c.length();
+ sal_Int32 l = c.length();
if( l == 0 )
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 );
*end = '\0';
- pData->length = end - pData->buffer;
+ pData->length = l;
return *this;
}
#endif
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 2c56443e8219..662e215c0370 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -349,7 +349,7 @@ public:
if (l != 0)
{
sal_Unicode* end = c.addData( pData->buffer );
- pData->length = end - pData->buffer;
+ pData->length = l;
*end = '\0';
// TODO realloc in case pData->length is noticeably smaller than l?
}
@@ -445,13 +445,14 @@ public:
template< typename T1, typename T2 >
OUString& operator+=( const OUStringConcat< T1, T2 >& c )
{
- const int l = c.length();
+ sal_Int32 l = c.length();
if( l == 0 )
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 );
*end = '\0';
- pData->length = end - pData->buffer;
+ pData->length = l;
return *this;
}
#endif