summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>2012-04-24 22:18:03 +0200
committerBernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>2012-04-24 22:18:03 +0200
commitbb851b75cc030c37b6a0ce0ce7580283c2c14fd5 (patch)
tree1278eaf93b252bdf3aedc44924e8d39157308742
parent8270f131d9ad93229e83e6c46b28516452814942 (diff)
downloadbase-bb851b75cc030c37b6a0ce0ce7580283c2c14fd5.tar.gz
Revert "Revert "frameworks/base: Fix various aliasing violations""
This reverts commit 634a905618c37b153a06559433f31ab2a10a920d.
-rw-r--r--core/jni/Android.mk1
-rw-r--r--libs/hwui/FontRenderer.cpp9
-rw-r--r--libs/hwui/ShapeCache.h34
-rw-r--r--libs/hwui/TextDropShadowCache.h4
-rw-r--r--media/libstagefright/codecs/avc/enc/src/motion_comp.cpp8
-rw-r--r--media/libstagefright/httplive/LiveSession.cpp5
-rw-r--r--media/libstagefright/rtsp/ARTPConnection.cpp23
-rw-r--r--media/libstagefright/rtsp/ARTSPConnection.cpp7
-rw-r--r--media/libstagefright/rtsp/MyHandler.h16
9 files changed, 69 insertions, 38 deletions
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 1e94bafb9df4..93fd5fb0d449 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -4,6 +4,7 @@ include $(CLEAR_VARS)
LOCAL_CFLAGS += -DHAVE_CONFIG_H -DKHTML_NO_EXCEPTIONS -DGKWQ_NO_JAVA
LOCAL_CFLAGS += -DNO_SUPPORT_JS_BINDING -DQT_NO_WHEELEVENT -DKHTML_NO_XBL
LOCAL_CFLAGS += -U__APPLE__
+LOCAL_CFLAGS += -fno-strict-aliasing
ifeq ($(TARGET_ARCH), arm)
LOCAL_CFLAGS += -DPACKED="__attribute__ ((packed))"
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp
index 158f78503689..49c25f673fa7 100644
--- a/libs/hwui/FontRenderer.cpp
+++ b/libs/hwui/FontRenderer.cpp
@@ -692,12 +692,15 @@ void FontRenderer::setFont(SkPaint* paint, uint32_t fontId, float fontSize) {
}
const float skewX = paint->getTextSkewX();
- uint32_t italicStyle = *(uint32_t*) &skewX;
+ uint32_t italicStyle;
+ memcpy(&italicStyle, &skewX, sizeof(italicStyle));
const float scaleXFloat = paint->getTextScaleX();
- uint32_t scaleX = *(uint32_t*) &scaleXFloat;
+ uint32_t scaleX;
+ memcpy(&scaleX, &scaleXFloat, sizeof(scaleX));
SkPaint::Style style = paint->getStyle();
const float strokeWidthFloat = paint->getStrokeWidth();
- uint32_t strokeWidth = *(uint32_t*) &strokeWidthFloat;
+ uint32_t strokeWidth;
+ memcpy(&strokeWidth, &strokeWidthFloat, sizeof(strokeWidth));
mCurrentFont = Font::create(this, fontId, fontSize, flags, italicStyle,
scaleX, style, strokeWidth);
diff --git a/libs/hwui/ShapeCache.h b/libs/hwui/ShapeCache.h
index 0660b690a1cd..0b37828f8dee 100644
--- a/libs/hwui/ShapeCache.h
+++ b/libs/hwui/ShapeCache.h
@@ -90,9 +90,9 @@ struct ShapeCacheEntry {
cap = SkPaint::kDefault_Cap;
style = SkPaint::kFill_Style;
float v = 4.0f;
- miter = *(uint32_t*) &v;
+ memcpy(&miter, &v, sizeof(miter));
v = 1.0f;
- strokeWidth = *(uint32_t*) &v;
+ memcpy(&strokeWidth, &v, sizeof(strokeWidth));
pathEffect = NULL;
}
@@ -101,9 +101,9 @@ struct ShapeCacheEntry {
join = paint->getStrokeJoin();
cap = paint->getStrokeCap();
float v = paint->getStrokeMiter();
- miter = *(uint32_t*) &v;
+ memcpy(&miter, &v, sizeof(miter));
v = paint->getStrokeWidth();
- strokeWidth = *(uint32_t*) &v;
+ memcpy(&strokeWidth, &v, sizeof(strokeWidth));
style = paint->getStyle();
pathEffect = paint->getPathEffect();
}
@@ -148,10 +148,10 @@ protected:
struct RoundRectShapeCacheEntry: public ShapeCacheEntry {
RoundRectShapeCacheEntry(float width, float height, float rx, float ry, SkPaint* paint):
ShapeCacheEntry(ShapeCacheEntry::kShapeRoundRect, paint) {
- mWidth = *(uint32_t*) &width;
- mHeight = *(uint32_t*) &height;
- mRx = *(uint32_t*) &rx;
- mRy = *(uint32_t*) &ry;
+ memcpy(&mWidth, &width, sizeof(mWidth));
+ memcpy(&mHeight, &height, sizeof(mHeight));
+ memcpy(&mRx, &rx, sizeof(mRx));
+ memcpy(&mRy, &ry, sizeof(mRy));
}
RoundRectShapeCacheEntry(): ShapeCacheEntry() {
@@ -185,7 +185,7 @@ private:
struct CircleShapeCacheEntry: public ShapeCacheEntry {
CircleShapeCacheEntry(float radius, SkPaint* paint):
ShapeCacheEntry(ShapeCacheEntry::kShapeCircle, paint) {
- mRadius = *(uint32_t*) &radius;
+ memcpy(&mRadius, &radius, sizeof(mRadius));
}
CircleShapeCacheEntry(): ShapeCacheEntry() {
@@ -207,8 +207,8 @@ private:
struct OvalShapeCacheEntry: public ShapeCacheEntry {
OvalShapeCacheEntry(float width, float height, SkPaint* paint):
ShapeCacheEntry(ShapeCacheEntry::kShapeOval, paint) {
- mWidth = *(uint32_t*) &width;
- mHeight = *(uint32_t*) &height;
+ memcpy(&mWidth, &width, sizeof(mWidth));
+ memcpy(&mHeight, &height, sizeof(mHeight));
}
OvalShapeCacheEntry(): ShapeCacheEntry() {
@@ -233,8 +233,8 @@ private:
struct RectShapeCacheEntry: public ShapeCacheEntry {
RectShapeCacheEntry(float width, float height, SkPaint* paint):
ShapeCacheEntry(ShapeCacheEntry::kShapeRect, paint) {
- mWidth = *(uint32_t*) &width;
- mHeight = *(uint32_t*) &height;
+ memcpy(&mWidth, &width, sizeof(mWidth));
+ memcpy(&mHeight, &height, sizeof(mHeight));
}
RectShapeCacheEntry(): ShapeCacheEntry() {
@@ -260,10 +260,10 @@ struct ArcShapeCacheEntry: public ShapeCacheEntry {
ArcShapeCacheEntry(float width, float height, float startAngle, float sweepAngle,
bool useCenter, SkPaint* paint):
ShapeCacheEntry(ShapeCacheEntry::kShapeArc, paint) {
- mWidth = *(uint32_t*) &width;
- mHeight = *(uint32_t*) &height;
- mStartAngle = *(uint32_t*) &startAngle;
- mSweepAngle = *(uint32_t*) &sweepAngle;
+ memcpy(&mWidth, &width, sizeof(mWidth));
+ memcpy(&mHeight, &height, sizeof(mHeight));
+ memcpy(&mStartAngle, &startAngle, sizeof(mStartAngle));
+ memcpy(&mSweepAngle, &sweepAngle, sizeof(mSweepAngle));
mUseCenter = useCenter ? 1 : 0;
}
diff --git a/libs/hwui/TextDropShadowCache.h b/libs/hwui/TextDropShadowCache.h
index e2bdde1eca89..35eb4cc9f571 100644
--- a/libs/hwui/TextDropShadowCache.h
+++ b/libs/hwui/TextDropShadowCache.h
@@ -49,10 +49,10 @@ struct ShadowText {
}
const float skewX = paint->getTextSkewX();
- italicStyle = *(uint32_t*) &skewX;
+ memcpy(&italicStyle, &skewX, sizeof(italicStyle));
const float scaleXFloat = paint->getTextScaleX();
- scaleX = *(uint32_t*) &scaleXFloat;
+ memcpy(&scaleX, &scaleXFloat, sizeof(scaleX));
}
~ShadowText() {
diff --git a/media/libstagefright/codecs/avc/enc/src/motion_comp.cpp b/media/libstagefright/codecs/avc/enc/src/motion_comp.cpp
index ac62d782c83d..fff65ebab0dc 100644
--- a/media/libstagefright/codecs/avc/enc/src/motion_comp.cpp
+++ b/media/libstagefright/codecs/avc/enc/src/motion_comp.cpp
@@ -1315,7 +1315,11 @@ void eDiagonalInterpMC(uint8 *in1, uint8 *in2, int inpitch,
int result;
uint8 *p_cur, *p_ref, *p_tmp8;
int curr_offset, ref_offset;
- uint8 tmp_res[24][24], tmp_in[24][24];
+ union {
+ uint8 tmp_res[24][24];
+ uint32 tmp_res32[24][24/4];
+ };
+ uint8 tmp_in[24][24];
uint32 *p_tmp;
uint32 tmp, pkres, tmp_result;
int32 r0, r1, r2, r3, r4, r5;
@@ -1333,7 +1337,7 @@ void eDiagonalInterpMC(uint8 *in1, uint8 *in2, int inpitch,
ref_offset = 24-blkwidth;
}*/
- p_tmp = (uint32*) & (tmp_res[0][0]);
+ p_tmp = & (tmp_res32[0][0]);
for (j = blkheight; j > 0; j--)
{
r13 = 0;
diff --git a/media/libstagefright/httplive/LiveSession.cpp b/media/libstagefright/httplive/LiveSession.cpp
index f67cdace819c..a13ee0b35a0e 100644
--- a/media/libstagefright/httplive/LiveSession.cpp
+++ b/media/libstagefright/httplive/LiveSession.cpp
@@ -192,8 +192,9 @@ void LiveSession::onConnect(const sp<AMessage> &msg) {
sp<AMessage> meta;
playlist->itemAt(i, &item.mURI, &meta);
- unsigned long bandwidth;
- CHECK(meta->findInt32("bandwidth", (int32_t *)&item.mBandwidth));
+ int32_t bandwidth;
+ CHECK(meta->findInt32("bandwidth", &bandwidth));
+ item.mBandwidth = bandwidth;
mBandwidthItems.push(item);
}
diff --git a/media/libstagefright/rtsp/ARTPConnection.cpp b/media/libstagefright/rtsp/ARTPConnection.cpp
index cd374e2a2017..738d1d7376a9 100644
--- a/media/libstagefright/rtsp/ARTPConnection.cpp
+++ b/media/libstagefright/rtsp/ARTPConnection.cpp
@@ -120,21 +120,24 @@ void ARTPConnection::MakePortPair(
start &= ~1;
for (unsigned port = start; port < 65536; port += 2) {
- struct sockaddr_in addr;
+ union {
+ struct sockaddr_in addr;
+ struct sockaddr addr_generic;
+ };
memset(addr.sin_zero, 0, sizeof(addr.sin_zero));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(port);
if (bind(*rtpSocket,
- (const struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ &addr_generic, sizeof(addr)) < 0) {
continue;
}
addr.sin_port = htons(port + 1);
if (bind(*rtcpSocket,
- (const struct sockaddr *)&addr, sizeof(addr)) == 0) {
+ &addr_generic, sizeof(addr)) == 0) {
*rtpPort = port;
return;
}
@@ -340,9 +343,14 @@ void ARTPConnection::onPollStreams() {
ssize_t n;
do {
+ union {
+ sockaddr_in *sa_in;
+ sockaddr *sa;
+ };
+ sa_in = &s->mRemoteRTCPAddr;
n = sendto(
s->mRTCPSocket, buffer->data(), buffer->size(), 0,
- (const struct sockaddr *)&s->mRemoteRTCPAddr,
+ sa,
sizeof(s->mRemoteRTCPAddr));
} while (n < 0 && errno == EINTR);
@@ -381,12 +389,17 @@ status_t ARTPConnection::receive(StreamInfo *s, bool receiveRTP) {
ssize_t nbytes;
do {
+ union {
+ sockaddr_in *sa_in;
+ sockaddr *sa;
+ };
+ sa_in = &s->mRemoteRTCPAddr;
nbytes = recvfrom(
receiveRTP ? s->mRTPSocket : s->mRTCPSocket,
buffer->data(),
buffer->capacity(),
0,
- remoteAddrLen > 0 ? (struct sockaddr *)&s->mRemoteRTCPAddr : NULL,
+ remoteAddrLen > 0 ? sa : NULL,
remoteAddrLen > 0 ? &remoteAddrLen : NULL);
} while (nbytes < 0 && errno == EINTR);
diff --git a/media/libstagefright/rtsp/ARTSPConnection.cpp b/media/libstagefright/rtsp/ARTSPConnection.cpp
index 380b3dcdcf9a..353eb08a527e 100644
--- a/media/libstagefright/rtsp/ARTSPConnection.cpp
+++ b/media/libstagefright/rtsp/ARTSPConnection.cpp
@@ -268,14 +268,17 @@ void ARTSPConnection::onConnect(const sp<AMessage> &msg) {
MakeSocketBlocking(mSocket, false);
- struct sockaddr_in remote;
+ union {
+ struct sockaddr_in remote;
+ struct sockaddr remote_generic;
+ };
memset(remote.sin_zero, 0, sizeof(remote.sin_zero));
remote.sin_family = AF_INET;
remote.sin_addr.s_addr = *(in_addr_t *)ent->h_addr;
remote.sin_port = htons(port);
int err = ::connect(
- mSocket, (const struct sockaddr *)&remote, sizeof(remote));
+ mSocket, &remote_generic, sizeof(remote));
reply->setInt32("server-ip", ntohl(remote.sin_addr.s_addr));
diff --git a/media/libstagefright/rtsp/MyHandler.h b/media/libstagefright/rtsp/MyHandler.h
index 5a95f9cfc35c..388d5d994d38 100644
--- a/media/libstagefright/rtsp/MyHandler.h
+++ b/media/libstagefright/rtsp/MyHandler.h
@@ -197,9 +197,12 @@ struct MyHandler : public AHandler {
}
static void addSDES(int s, const sp<ABuffer> &buffer) {
- struct sockaddr_in addr;
+ union {
+ struct sockaddr_in addr;
+ struct sockaddr addr_generic;
+ };
socklen_t addrSize = sizeof(addr);
- CHECK_EQ(0, getsockname(s, (sockaddr *)&addr, &addrSize));
+ CHECK_EQ(0, getsockname(s, &addr_generic, &addrSize));
uint8_t *data = buffer->data() + buffer->size();
data[0] = 0x80 | 1;
@@ -255,7 +258,10 @@ struct MyHandler : public AHandler {
// rtp/rtcp ports to poke a hole into the firewall for future incoming
// packets. We're going to send an RR/SDES RTCP packet to both of them.
bool pokeAHole(int rtpSocket, int rtcpSocket, const AString &transport) {
- struct sockaddr_in addr;
+ union {
+ struct sockaddr_in addr;
+ struct sockaddr addr_generic;
+ };
memset(addr.sin_zero, 0, sizeof(addr.sin_zero));
addr.sin_family = AF_INET;
@@ -324,7 +330,7 @@ struct MyHandler : public AHandler {
ssize_t n = sendto(
rtpSocket, buf->data(), buf->size(), 0,
- (const sockaddr *)&addr, sizeof(addr));
+ &addr_generic, sizeof(addr));
if (n < (ssize_t)buf->size()) {
LOGE("failed to poke a hole for RTP packets");
@@ -335,7 +341,7 @@ struct MyHandler : public AHandler {
n = sendto(
rtcpSocket, buf->data(), buf->size(), 0,
- (const sockaddr *)&addr, sizeof(addr));
+ &addr_generic, sizeof(addr));
if (n < (ssize_t)buf->size()) {
LOGE("failed to poke a hole for RTCP packets");