avoid GCC warnings about breaking strict aliasing rules

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51508 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Paul Cornett
2008-02-02 21:52:26 +00:00
parent 7f85af8223
commit e8769ed11c
4 changed files with 32 additions and 29 deletions

View File

@@ -1981,7 +1981,7 @@ wxMBConv_iconv::wxMBConv_iconv(const char *name)
if ( m2w != ICONV_T_INVALID ) if ( m2w != ICONV_T_INVALID )
{ {
char buf[2], *bufPtr; char buf[2], *bufPtr;
wchar_t wbuf[2], *wbufPtr; wchar_t wbuf[2];
size_t insz, outsz; size_t insz, outsz;
size_t res; size_t res;
@@ -1990,12 +1990,12 @@ wxMBConv_iconv::wxMBConv_iconv(const char *name)
wbuf[0] = 0; wbuf[0] = 0;
insz = 2; insz = 2;
outsz = SIZEOF_WCHAR_T * 2; outsz = SIZEOF_WCHAR_T * 2;
wbufPtr = wbuf; char* wbufPtr = (char*)wbuf;
bufPtr = buf; bufPtr = buf;
res = iconv( res = iconv(
m2w, ICONV_CHAR_CAST(&bufPtr), &insz, m2w, ICONV_CHAR_CAST(&bufPtr), &insz,
(char**)&wbufPtr, &outsz); &wbufPtr, &outsz);
if (ICONV_FAILED(res, insz)) if (ICONV_FAILED(res, insz))
{ {
@@ -2091,16 +2091,16 @@ size_t wxMBConv_iconv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
size_t outbuf = n * SIZEOF_WCHAR_T; size_t outbuf = n * SIZEOF_WCHAR_T;
size_t res, cres; size_t res, cres;
// VS: Use these instead of psz, buf because iconv() modifies its arguments:
wchar_t *bufPtr = buf;
const char *pszPtr = psz; const char *pszPtr = psz;
if (buf) if (buf)
{ {
char* bufPtr = (char*)buf;
// have destination buffer, convert there // have destination buffer, convert there
cres = iconv(m2w, cres = iconv(m2w,
ICONV_CHAR_CAST(&pszPtr), &inbuf, ICONV_CHAR_CAST(&pszPtr), &inbuf,
(char**)&bufPtr, &outbuf); &bufPtr, &outbuf);
res = n - (outbuf / SIZEOF_WCHAR_T); res = n - (outbuf / SIZEOF_WCHAR_T);
if (ms_wcNeedsSwap) if (ms_wcNeedsSwap)
@@ -2123,12 +2123,12 @@ size_t wxMBConv_iconv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
do do
{ {
bufPtr = tbuf; char* bufPtr = (char*)tbuf;
outbuf = 8 * SIZEOF_WCHAR_T; outbuf = 8 * SIZEOF_WCHAR_T;
cres = iconv(m2w, cres = iconv(m2w,
ICONV_CHAR_CAST(&pszPtr), &inbuf, ICONV_CHAR_CAST(&pszPtr), &inbuf,
(char**)&bufPtr, &outbuf ); &bufPtr, &outbuf );
res += 8 - (outbuf / SIZEOF_WCHAR_T); res += 8 - (outbuf / SIZEOF_WCHAR_T);
} }
@@ -2153,8 +2153,8 @@ size_t wxMBConv_iconv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
#endif #endif
size_t inlen = wxWcslen(psz); size_t inlen = wxWcslen(psz);
size_t inbuf = inlen * SIZEOF_WCHAR_T; size_t inbuflen = inlen * SIZEOF_WCHAR_T;
size_t outbuf = n; size_t outbuflen = n;
size_t res, cres; size_t res, cres;
wchar_t *tmpbuf = 0; wchar_t *tmpbuf = 0;
@@ -2164,7 +2164,7 @@ size_t wxMBConv_iconv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
// need to copy to temp buffer to switch endianness // need to copy to temp buffer to switch endianness
// (doing WC_BSWAP twice on the original buffer won't help, as it // (doing WC_BSWAP twice on the original buffer won't help, as it
// could be in read-only memory, or be accessed in some other thread) // could be in read-only memory, or be accessed in some other thread)
tmpbuf = (wchar_t *)malloc(inbuf + SIZEOF_WCHAR_T); tmpbuf = (wchar_t *)malloc(inbuflen + SIZEOF_WCHAR_T);
for ( size_t i = 0; i < inlen; i++ ) for ( size_t i = 0; i < inlen; i++ )
tmpbuf[n] = WC_BSWAP(psz[i]); tmpbuf[n] = WC_BSWAP(psz[i]);
@@ -2172,12 +2172,13 @@ size_t wxMBConv_iconv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
psz = tmpbuf; psz = tmpbuf;
} }
char* inbuf = (char*)psz;
if (buf) if (buf)
{ {
// have destination buffer, convert there // have destination buffer, convert there
cres = iconv( w2m, ICONV_CHAR_CAST(&psz), &inbuf, &buf, &outbuf ); cres = iconv(w2m, ICONV_CHAR_CAST(&inbuf), &inbuflen, &buf, &outbuflen);
res = n - outbuf; res = n - outbuflen;
// NB: iconv was given only wcslen(psz) characters on input, and so // NB: iconv was given only wcslen(psz) characters on input, and so
// it couldn't convert the trailing zero. Let's do it ourselves // it couldn't convert the trailing zero. Let's do it ourselves
@@ -2194,11 +2195,11 @@ size_t wxMBConv_iconv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
do do
{ {
buf = tbuf; buf = tbuf;
outbuf = 16; outbuflen = 16;
cres = iconv( w2m, ICONV_CHAR_CAST(&psz), &inbuf, &buf, &outbuf ); cres = iconv(w2m, ICONV_CHAR_CAST(&inbuf), &inbuflen, &buf, &outbuflen);
res += 16 - outbuf; res += 16 - outbuflen;
} }
while ((cres == (size_t)-1) && (errno == E2BIG)); while ((cres == (size_t)-1) && (errno == E2BIG));
} }
@@ -2208,7 +2209,7 @@ size_t wxMBConv_iconv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
free(tmpbuf); free(tmpbuf);
} }
if (ICONV_FAILED(cres, inbuf)) if (ICONV_FAILED(cres, inbuflen))
{ {
wxLogTrace(TRACE_STRCONV, wxT("iconv failed: %s"), wxSysErrorMsg(wxSysErrorCode())); wxLogTrace(TRACE_STRCONV, wxT("iconv failed: %s"), wxSysErrorMsg(wxSysErrorCode()));
return wxCONV_FAILED; return wxCONV_FAILED;

View File

@@ -414,7 +414,7 @@ static bool GetFrameExtents(GdkWindow* window, int* left, int* right, int* top,
Atom type; Atom type;
int format; int format;
gulong nitems, bytes_after; gulong nitems, bytes_after;
long* data = NULL; guchar* data;
success = XGetWindowProperty( success = XGetWindowProperty(
gdk_x11_drawable_get_xdisplay(window), gdk_x11_drawable_get_xdisplay(window),
gdk_x11_drawable_get_xid(window), gdk_x11_drawable_get_xid(window),
@@ -422,17 +422,18 @@ static bool GetFrameExtents(GdkWindow* window, int* left, int* right, int* top,
0, 4, 0, 4,
false, false,
XA_CARDINAL, XA_CARDINAL,
&type, &format, &nitems, &bytes_after, (guchar**)&data &type, &format, &nitems, &bytes_after, &data
) == Success; ) == Success;
if (success) if (success)
{ {
success = data && nitems == 4; success = data && nitems == 4;
if (success) if (success)
{ {
if (left) *left = int(data[0]); long* p = (long*)data;
if (right) *right = int(data[1]); if (left) *left = int(p[0]);
if (top) *top = int(data[2]); if (right) *right = int(p[1]);
if (bottom) *bottom = int(data[3]); if (top) *top = int(p[2]);
if (bottom) *bottom = int(p[3]);
} }
if (data) if (data)
XFree(data); XFree(data);

View File

@@ -392,17 +392,18 @@ static gboolean property_notify_event(
Atom type; Atom type;
int format; int format;
gulong nitems, bytes_after; gulong nitems, bytes_after;
long* data = NULL; guchar* data;
Status status = XGetWindowProperty( Status status = XGetWindowProperty(
gdk_x11_drawable_get_xdisplay(event->window), gdk_x11_drawable_get_xdisplay(event->window),
gdk_x11_drawable_get_xid(event->window), gdk_x11_drawable_get_xid(event->window),
xproperty, xproperty,
0, 4, false, XA_CARDINAL, 0, 4, false, XA_CARDINAL,
&type, &format, &nitems, &bytes_after, (guchar**)&data); &type, &format, &nitems, &bytes_after, &data);
if (status == Success && data && nitems == 4) if (status == Success && data && nitems == 4)
{ {
long* p = (long*)data;
const wxSize decorSize = const wxSize decorSize =
wxSize(int(data[0] + data[1]), int(data[2] + data[3])); wxSize(int(p[0] + p[1]), int(p[2] + p[3]));
if (win->m_decorSize != decorSize) if (win->m_decorSize != decorSize)
{ {
const wxSize diff = decorSize - win->m_decorSize; const wxSize diff = decorSize - win->m_decorSize;

View File

@@ -382,20 +382,20 @@ static bool wxKwinRunning(Display *display, Window rootWnd)
{ {
wxMAKE_ATOM(KWIN_RUNNING, display); wxMAKE_ATOM(KWIN_RUNNING, display);
long *data; unsigned char* data;
Atom type; Atom type;
int format; int format;
unsigned long nitems, after; unsigned long nitems, after;
if (XGetWindowProperty(display, rootWnd, if (XGetWindowProperty(display, rootWnd,
KWIN_RUNNING, 0, 1, False, KWIN_RUNNING, KWIN_RUNNING, 0, 1, False, KWIN_RUNNING,
&type, &format, &nitems, &after, &type, &format, &nitems, &after,
(unsigned char**)&data) != Success) &data) != Success)
{ {
return false; return false;
} }
bool retval = (type == KWIN_RUNNING && bool retval = (type == KWIN_RUNNING &&
nitems == 1 && data && data[0] == 1); nitems == 1 && data && ((long*)data)[0] == 1);
XFree(data); XFree(data);
return retval; return retval;
} }