summaryrefslogtreecommitdiffstats
path: root/src/resources
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/resources
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/resources')
-rw-r--r--src/resources/map.c12
1 files changed, 11 insertions, 1 deletions
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");