summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Rudolph <[email protected]>2016-09-01 18:07:55 +0200
committerAxel Davy <[email protected]>2016-10-10 23:43:51 +0200
commit7afab4ad39b5c479d5c986483511c68b92c31219 (patch)
tree8c7f29259c7e3465b64cddeda96b40ea07678c36
parentb9f31111ac5630a9cdfe4ceb404bdfdd7d804424 (diff)
st/nine: Fix compiler warning
Use strict aliasing in SetPrivateData and struct pheader. Casting char[1] to IUnknown** isn't allowed in strict aliasing. Compute pointer to body by adding size of header to header pointer. Signed-off-by: Patrick Rudolph <[email protected]> Reviewed-by: Axel Davy <[email protected]>
-rw-r--r--src/gallium/state_trackers/nine/iunknown.c14
-rw-r--r--src/gallium/state_trackers/nine/nine_pdata.h4
2 files changed, 11 insertions, 7 deletions
diff --git a/src/gallium/state_trackers/nine/iunknown.c b/src/gallium/state_trackers/nine/iunknown.c
index 541c528591a..c0d2b0db019 100644
--- a/src/gallium/state_trackers/nine/iunknown.c
+++ b/src/gallium/state_trackers/nine/iunknown.c
@@ -159,6 +159,7 @@ NineUnknown_SetPrivateData( struct NineUnknown *This,
struct pheader *header;
const void *user_data = pData;
char guid_str[64];
+ void *header_data;
DBG("This=%p GUID=%s pData=%p SizeOfData=%u Flags=%x\n",
This, GUID_sprintf(guid_str, refguid), pData, SizeOfData, Flags);
@@ -167,7 +168,7 @@ NineUnknown_SetPrivateData( struct NineUnknown *This,
user_assert(SizeOfData == sizeof(IUnknown *), D3DERR_INVALIDCALL);
/* data consists of a header and the actual data. avoiding 2 mallocs */
- header = CALLOC_VARIANT_LENGTH_STRUCT(pheader, SizeOfData-1);
+ header = CALLOC_VARIANT_LENGTH_STRUCT(pheader, SizeOfData);
if (!header) { return E_OUTOFMEMORY; }
header->unknown = (Flags & D3DSPD_IUNKNOWN) ? TRUE : FALSE;
@@ -182,12 +183,13 @@ NineUnknown_SetPrivateData( struct NineUnknown *This,
}
header->size = SizeOfData;
- memcpy(header->data, user_data, header->size);
+ header_data = (void *)header + sizeof(*header);
+ memcpy(header_data, user_data, header->size);
memcpy(&header->guid, refguid, sizeof(header->guid));
err = util_hash_table_set(This->pdata, &header->guid, header);
if (err == PIPE_OK) {
- if (header->unknown) { IUnknown_AddRef(*(IUnknown **)header->data); }
+ if (header->unknown) { IUnknown_AddRef(*(IUnknown **)header_data); }
return D3D_OK;
}
@@ -206,6 +208,7 @@ NineUnknown_GetPrivateData( struct NineUnknown *This,
struct pheader *header;
DWORD sizeofdata;
char guid_str[64];
+ void *header_data;
DBG("This=%p GUID=%s pData=%p pSizeOfData=%p\n",
This, GUID_sprintf(guid_str, refguid), pData, pSizeOfData);
@@ -224,8 +227,9 @@ NineUnknown_GetPrivateData( struct NineUnknown *This,
return D3DERR_MOREDATA;
}
- if (header->unknown) { IUnknown_AddRef(*(IUnknown **)header->data); }
- memcpy(pData, header->data, header->size);
+ header_data = (void *)header + sizeof(*header);
+ if (header->unknown) { IUnknown_AddRef(*(IUnknown **)header_data); }
+ memcpy(pData, header_data, header->size);
return D3D_OK;
}
diff --git a/src/gallium/state_trackers/nine/nine_pdata.h b/src/gallium/state_trackers/nine/nine_pdata.h
index 0e9a2aa7160..92e50c8a72c 100644
--- a/src/gallium/state_trackers/nine/nine_pdata.h
+++ b/src/gallium/state_trackers/nine/nine_pdata.h
@@ -7,7 +7,6 @@ struct pheader
boolean unknown;
GUID guid;
DWORD size;
- char data[1];
};
static int
@@ -36,8 +35,9 @@ ht_guid_delete( void *key,
void *data )
{
struct pheader *header = value;
+ void *header_data = (void *)header + sizeof(*header);
- if (header->unknown) { IUnknown_Release(*(IUnknown **)header->data); }
+ if (header->unknown) { IUnknown_Release(*(IUnknown **)header_data); }
FREE(header);
return PIPE_OK;