Browse Source

Fix -Wcast-align problems in examples

pull/297/head
Sami Vaarala 9 years ago
parent
commit
5fd84da843
  1. 6
      examples/alloc-hybrid/duk_alloc_hybrid.c
  2. 4
      examples/alloc-logging/duk_alloc_logging.c
  3. 14
      examples/alloc-torture/duk_alloc_torture.c

6
examples/alloc-hybrid/duk_alloc_hybrid.c

@ -127,16 +127,16 @@ void *duk_alloc_hybrid_init(void) {
hdr->alloc_start = p;
hdr->alloc_end = p + pool_sizes[i].size * pool_sizes[i].count;
hdr->free = (pool_free_entry *) p;
hdr->free = (pool_free_entry *) (void *) p;
hdr->size = pool_sizes[i].size;
hdr->count = pool_sizes[i].count;
for (j = 0; j < pool_sizes[i].count; j++) {
pool_free_entry *ent = (pool_free_entry *) p;
pool_free_entry *ent = (pool_free_entry *) (void *) p;
if (j == pool_sizes[i].count - 1) {
ent->next = (pool_free_entry *) NULL;
} else {
ent->next = (pool_free_entry *) (p + pool_sizes[i].size);
ent->next = (pool_free_entry *) (void *) (p + pool_sizes[i].size);
}
p += pool_sizes[i].size;
}

4
examples/alloc-logging/duk_alloc_logging.c

@ -86,7 +86,7 @@ void *duk_realloc_logging(void *udata, void *ptr, duk_size_t size) {
*/
if (ptr) {
hdr = (alloc_hdr *) ((unsigned char *) ptr - sizeof(alloc_hdr));
hdr = (alloc_hdr *) (void *) ((unsigned char *) ptr - sizeof(alloc_hdr));
old_size = hdr->u.sz;
if (size == 0) {
@ -132,7 +132,7 @@ void duk_free_logging(void *udata, void *ptr) {
write_log("F NULL 0\n");
return;
}
hdr = (alloc_hdr *) ((unsigned char *) ptr - sizeof(alloc_hdr));
hdr = (alloc_hdr *) (void *) ((unsigned char *) ptr - sizeof(alloc_hdr));
write_log("F %p %ld\n", ptr, (long) hdr->u.sz);
free((void *) hdr);
}

14
examples/alloc-torture/duk_alloc_torture.c

@ -84,7 +84,7 @@ void *duk_alloc_torture(void *udata, duk_size_t size) {
return NULL;
}
((alloc_hdr *) p)->u.sz = size;
((alloc_hdr *) (void *) p)->u.sz = size;
p += sizeof(alloc_hdr);
memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE);
p += RED_ZONE_SIZE;
@ -108,8 +108,8 @@ void *duk_realloc_torture(void *udata, void *ptr, duk_size_t size) {
if (ptr) {
old_p = (unsigned char *) ptr - sizeof(alloc_hdr) - RED_ZONE_SIZE;
old_size = ((alloc_hdr *) old_p)->u.sz;
check_red_zone((alloc_hdr *) old_p);
old_size = ((alloc_hdr *) (void *) old_p)->u.sz;
check_red_zone((alloc_hdr *) (void *) old_p);
if (size == 0) {
memset((void *) old_p, WIPE_BYTE, old_size + sizeof(alloc_hdr) + 2 * RED_ZONE_SIZE);
@ -122,7 +122,7 @@ void *duk_realloc_torture(void *udata, void *ptr, duk_size_t size) {
return NULL;
}
((alloc_hdr *) p)->u.sz = size;
((alloc_hdr *) (void *) p)->u.sz = size;
p += sizeof(alloc_hdr);
memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE);
p += RED_ZONE_SIZE;
@ -150,7 +150,7 @@ void *duk_realloc_torture(void *udata, void *ptr, duk_size_t size) {
return NULL;
}
((alloc_hdr *) p)->u.sz = size;
((alloc_hdr *) (void *) p)->u.sz = size;
p += sizeof(alloc_hdr);
memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE);
p += RED_ZONE_SIZE;
@ -174,9 +174,9 @@ void duk_free_torture(void *udata, void *ptr) {
}
p = (unsigned char *) ptr - sizeof(alloc_hdr) - RED_ZONE_SIZE;
old_size = ((alloc_hdr *) p)->u.sz;
old_size = ((alloc_hdr *) (void *) p)->u.sz;
check_red_zone((alloc_hdr *) p);
check_red_zone((alloc_hdr *) (void *) p);
memset((void *) p, WIPE_BYTE, old_size + sizeof(alloc_hdr) + 2 * RED_ZONE_SIZE);
free((void *) p);
}

Loading…
Cancel
Save