shithub: pokecrystal

Download patch

ref: 2af6c6325365043164ac6afc4cee3d808c2ce1c7
parent: 79f3f3f4d5bb0fbe0d75596960ab72dcaffc16de
author: Lior Halphon <LIJI32@gmail.com>
date: Thu Apr 2 17:42:12 EDT 2020

Fix bad round, memset VLA

--- a/tools/gfx.c
+++ b/tools/gfx.c
@@ -104,7 +104,7 @@
 	if (Options.interleave) tile_size *= 2;
 	
 	// Make sure we have a whole number of tiles, round down if required
-	graphic->size &= tile_size - 1;
+	graphic->size &= ~(tile_size - 1);
 	
 	int i = 0;
 	for (int j = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) {
@@ -142,7 +142,7 @@
 	int num_tiles = 0;
 	
 	// Make sure we have a whole number of tiles, round down if required
-	graphic->size &= tile_size - 1;
+	graphic->size &= ~(tile_size - 1);
 	
 	for (int i = 0, j = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) {
 		while (j < graphic->size && tile_exists(&graphic->data[j], graphic->data, tile_size, num_tiles)) {
@@ -164,6 +164,7 @@
 
 bool flip_exists(uint8_t *tile, uint8_t *tiles, int tile_size, int num_tiles, bool xflip, bool yflip) {
 	uint8_t flip[tile_size];
+	memset(flip, 0, sizeof(flip));
 	int half_size = tile_size / 2;
 	for (int i = 0; i < tile_size; i++) {
 		int byte = i;
@@ -193,7 +194,7 @@
 	int num_tiles = 0;
 	
 	// Make sure we have a whole number of tiles, round down if required
-	graphic->size &= tile_size - 1;
+	graphic->size &= ~(tile_size - 1);
 	
 	for (int i = 0, j = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) {
 		while (j < graphic->size && flip_exists(&graphic->data[j], graphic->data, tile_size, num_tiles, xflip, yflip)) {