stlport: Fix strict aliasing violations
This patch fixes strict aliasing violations.
Forward-ported from Chao Yang <chao.yang@linaro.org>'s
patch for 2.3.5.
Signed-off-by: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
diff --git a/stlport/stl/_stdexcept_base.c b/stlport/stl/_stdexcept_base.c
index deb7056..e17b799 100644
--- a/stlport/stl/_stdexcept_base.c
+++ b/stlport/stl/_stdexcept_base.c
@@ -16,6 +16,12 @@
*
*/
+static inline size_t* local_cast(void* p){
+ union{void* p; size_t* size_t_p;}u_cast;
+ u_cast.p = p;
+ return u_cast.size_t_p;
+}
+
__Named_exception::__Named_exception(const string& __str) {
size_t __size = strlen(_STLP_PRIV __get_c_string(__str)) + 1;
if (__size > _S_bufsize) {
@@ -25,7 +31,7 @@
_M_name = _M_static_name;
}
else {
- *(__REINTERPRET_CAST(size_t*, &_M_static_name[0])) = __size * sizeof(char);
+ *(local_cast(&_M_static_name[0])) = __size * sizeof(char);
}
}
else {
@@ -48,7 +54,7 @@
_M_name = _M_static_name;
}
else {
- *(__REINTERPRET_CAST(size_t*, &_M_static_name[0])) = __size * sizeof(char);
+ *(local_cast(&_M_static_name[0])) = __size * sizeof(char);
}
}
else {
@@ -64,7 +70,7 @@
__Named_exception& __Named_exception::operator = (const __Named_exception& __x) {
size_t __size = strlen(__x._M_name) + 1;
- size_t __buf_size = _M_name != _M_static_name ? *(__REINTERPRET_CAST(size_t*, &_M_static_name[0])) : _S_bufsize;
+ size_t __buf_size = _M_name != _M_static_name ? *(local_cast(&_M_static_name[0])) : _S_bufsize;
if (__size > __buf_size) {
// Being here necessarily mean that we need to allocate a buffer:
if (_M_name != _M_static_name) free(_M_name);
@@ -74,7 +80,7 @@
_M_name = _M_static_name;
}
else {
- *(__REINTERPRET_CAST(size_t*, &_M_static_name[0])) = __size * sizeof(char);
+ *(local_cast(&_M_static_name[0])) = __size * sizeof(char);
}
}
#if !defined (_STLP_USE_SAFE_STRING_FUNCTIONS)