summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-02-18 16:33:08 (EST)
committer P. J. McDermott <pjm@nac.net>2013-02-18 16:33:08 (EST)
commitc250247b7be8b6a0942f7aaeaab95ad6fef933be (patch)
tree14765ae476db1ad3d757067c6e7ae19d466b680f /src
parentf158a79d0e8a2158f843ecfc5d7eaaa620828679 (diff)
downloadoverworld-rpg-c250247b7be8b6a0942f7aaeaab95ad6fef933be.zip
overworld-rpg-c250247b7be8b6a0942f7aaeaab95ad6fef933be.tar.gz
overworld-rpg-c250247b7be8b6a0942f7aaeaab95ad6fef933be.tar.bz2
Fix unsafe (char *)->(int *). Ensure byte order.
Diffstat (limited to 'src')
-rw-r--r--src/main.c4
-rw-r--r--src/resources/map.c12
2 files changed, 15 insertions, 1 deletions
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("</%s> (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");