diff options
author | Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org> | 2011-12-07 14:46:23 +0059 |
---|---|---|
committer | Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org> | 2011-12-17 11:55:30 +0059 |
commit | 03e7cf3b8467686d5ec804dabed517179237df03 (patch) | |
tree | 4e8d627e957fab073105f2f750be4a0b392833bd | |
parent | ba678fcefdb0f7b9458b97a07cee1123591960e3 (diff) | |
download | base-03e7cf3b8467686d5ec804dabed517179237df03.tar.gz |
frameworks/base: Fix aliasing violations
This makes it possible to build the code without
disabling the strict-aliasing optimization in gcc.
Signed-off-by: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
-rw-r--r-- | libs/utils/ResourceTypes.cpp | 2 | ||||
-rw-r--r-- | media/libmedia/Visualizer.cpp | 31 | ||||
-rw-r--r-- | opengl/libs/EGL/Loader.cpp | 6 | ||||
-rw-r--r-- | opengl/libs/GLES2_dbg/src/server.cpp | 15 |
4 files changed, 36 insertions, 18 deletions
diff --git a/libs/utils/ResourceTypes.cpp b/libs/utils/ResourceTypes.cpp index 6cf01c8d6887..37c98747d4ed 100644 --- a/libs/utils/ResourceTypes.cpp +++ b/libs/utils/ResourceTypes.cpp @@ -3130,7 +3130,7 @@ bool ResTable::stringToFloat(const char16_t* s, size_t len, Res_value* outValue) if (*end == 0) { if (outValue) { outValue->dataType = outValue->TYPE_FLOAT; - *(float*)(&outValue->data) = f; + memcpy(&outValue->data, &f, sizeof(float)); return true; } } diff --git a/media/libmedia/Visualizer.cpp b/media/libmedia/Visualizer.cpp index bf404819107d..6ea5a59d61da 100644 --- a/media/libmedia/Visualizer.cpp +++ b/media/libmedia/Visualizer.cpp @@ -138,13 +138,17 @@ status_t Visualizer::setCaptureSize(uint32_t size) return INVALID_OPERATION; } - uint32_t buf32[sizeof(effect_param_t) / sizeof(uint32_t) + 2]; - effect_param_t *p = (effect_param_t *)buf32; + union { + uint32_t buf32[sizeof(effect_param_t) / sizeof(uint32_t) + 2]; + effect_param_t bufp; + }; + effect_param_t *p = &bufp; p->psize = sizeof(uint32_t); p->vsize = sizeof(uint32_t); - *(int32_t *)p->data = VISUALIZER_PARAM_CAPTURE_SIZE; - *((int32_t *)p->data + 1)= size; + int32_t const vpcs = VISUALIZER_PARAM_CAPTURE_SIZE; + memcpy(&p->data, &vpcs, sizeof(vpcs)); + memcpy(&p->data+sizeof(int32_t), &size, sizeof(size)); status_t status = setParameter(p); LOGV("setCaptureSize size %d status %d p->status %d", size, status, p->status); @@ -271,21 +275,24 @@ void Visualizer::periodicCapture() uint32_t Visualizer::initCaptureSize() { - uint32_t buf32[sizeof(effect_param_t) / sizeof(uint32_t) + 2]; - effect_param_t *p = (effect_param_t *)buf32; + union { + uint32_t buf32[sizeof(effect_param_t) / sizeof(uint32_t) + 2]; + effect_param_t p; + }; - p->psize = sizeof(uint32_t); - p->vsize = sizeof(uint32_t); - *(int32_t *)p->data = VISUALIZER_PARAM_CAPTURE_SIZE; - status_t status = getParameter(p); + p.psize = sizeof(uint32_t); + p.vsize = sizeof(uint32_t); + int32_t const vpcs = VISUALIZER_PARAM_CAPTURE_SIZE; + memcpy(&p.data, &vpcs, sizeof(vpcs)); + status_t status = getParameter(&p); if (status == NO_ERROR) { - status = p->status; + status = p.status; } uint32_t size = 0; if (status == NO_ERROR) { - size = *((int32_t *)p->data + 1); + memcpy(&size, &p.data+sizeof(int32_t), sizeof(int32_t)); } mCaptureSize = size; diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp index 325193c7f44b..70eac548ce3e 100644 --- a/opengl/libs/EGL/Loader.cpp +++ b/opengl/libs/EGL/Loader.cpp @@ -311,16 +311,18 @@ void *Loader::load_driver(const char* kind, const char *tag, } if (mask & GLESv1_CM) { + void *gl=&cnx->hooks[GLESv1_INDEX]->gl; init_api(dso, gl_names, (__eglMustCastToProperFunctionPointerType*) - &cnx->hooks[GLESv1_INDEX]->gl, + gl, getProcAddress); } if (mask & GLESv2) { + void *gl=&cnx->hooks[GLESv2_INDEX]->gl; init_api(dso, gl_names, (__eglMustCastToProperFunctionPointerType*) - &cnx->hooks[GLESv2_INDEX]->gl, + gl, getProcAddress); } diff --git a/opengl/libs/GLES2_dbg/src/server.cpp b/opengl/libs/GLES2_dbg/src/server.cpp index 0c711bf200fe..80a2d08101a0 100644 --- a/opengl/libs/GLES2_dbg/src/server.cpp +++ b/opengl/libs/GLES2_dbg/src/server.cpp @@ -49,7 +49,16 @@ void StartDebugServer(const unsigned short port, const bool forceUseFile, return; LOGD("GLESv2_dbg: StartDebugServer create socket"); - struct sockaddr_in server = {}, client = {}; + union { + sockaddr_in server; + sockaddr server_generic; + }; + union { + sockaddr_in client; + sockaddr client_generic; + }; + server = {}; + client = {}; /* Create the TCP socket */ if (forceUseFile || (serverSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { @@ -66,7 +75,7 @@ void StartDebugServer(const unsigned short port, const bool forceUseFile, /* Bind the server socket */ socklen_t sizeofSockaddr_in = sizeof(sockaddr_in); - if (bind(serverSock, (struct sockaddr *) &server, + if (bind(serverSock, &server_generic, sizeof(server)) < 0) { Die("Failed to bind the server socket"); } @@ -80,7 +89,7 @@ void StartDebugServer(const unsigned short port, const bool forceUseFile, /* Wait for client connection */ if ((clientSock = - accept(serverSock, (struct sockaddr *) &client, + accept(serverSock, &client_generic, &sizeofSockaddr_in)) < 0) { Die("Failed to accept client connection"); } |