From c250247b7be8b6a0942f7aaeaab95ad6fef933be Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Mon, 18 Feb 2013 16:33:08 -0500 Subject: Fix unsafe (char *)->(int *). Ensure byte order. --- diff --git a/src/main.c b/src/main.c index fa7c7f6..dc85590 100644 --- a/src/main.c +++ b/src/main.c @@ -11,6 +11,7 @@ main(void) struct image *img; struct map_tileset *ts; struct map_exit *e; + int i; SDL_Rect imgrect, surfacerect; init(); @@ -30,6 +31,9 @@ main(void) e->target_map->width, e->target_map->height, e->target_x_coord, e->target_y_coord); } + for (i = 0; i < map->width * map->height; ++i) { + debug("%x", map->layers[LAYER_CHAR_BOT].tiles[i]); + } img = img_png_get("../forest-6-layer-test_ground.png"); img_png_free(img); diff --git a/src/resources/map.c b/src/resources/map.c index 2cc2f2a..514129d 100644 --- a/src/resources/map.c +++ b/src/resources/map.c @@ -623,6 +623,7 @@ tmx_data_end(void *pv, const char *name) size_t decomp_len; char *decoded_buf; char *decomp_buf; + size_t i; debug(" (data)", name); @@ -671,7 +672,16 @@ tmx_data_end(void *pv, const char *name) return; } free(ly->raw_data); - ly->tiles = (Uint32 *) decomp_buf; + ly->tiles = malloc(decomp_len); + for (i = 0; i < decomp_len / 4; ++i) { + /* Convert each tile GID to the system's byte order. */ + ly->tiles[i] = + (decomp_buf[i * 4 + 0] & 0xFF << 000) | + (decomp_buf[i * 4 + 1] & 0xFF << 010) | + (decomp_buf[i * 4 + 2] & 0xFF << 020) | + (decomp_buf[i * 4 + 3] & 0xFF << 030); + } + free(decomp_buf); xml_node_pop(p); } else { xml_unexpected_end_tag(p, name, "data"); -- cgit v0.9.1