shithub: rgbds

Download patch

ref: 004bc2e50ef04200a559b3ce8e8e6767a6142494
parent: af506985e5019ae540a76d13414cc4d020325d1f
author: stag019 <[email protected]>
date: Fri Oct 31 06:48:54 EDT 2014

Fix a few charmap bugs maybe?

--- a/src/asm/charmap.c
+++ b/src/asm/charmap.c
@@ -23,7 +23,7 @@
 #include "asm/main.h"
 #include "asm/output.h"
 
-struct Charmap globalCharmap;
+struct Charmap globalCharmap = {0};
 
 extern struct Section *pCurrentSection;
 
@@ -67,7 +67,7 @@
 charmap_Add(char *input, UBYTE output)
 {
 	int i, input_length;
-	char temp1i[CHARMAPLENGTH + 1], temp2i[CHARMAPLENGTH + 1], temp1o, temp2o;
+	char temp1i[CHARMAPLENGTH + 1], temp2i[CHARMAPLENGTH + 1], temp1o = 0, temp2o = 0;
 
 	struct Charmap *charmap;
 
@@ -79,7 +79,7 @@
 		}
 		else
 		{
-			if((charmap = (struct Charmap *) malloc(sizeof(struct Charmap))) == NULL)
+			if((charmap = (struct Charmap *) calloc(1, sizeof(struct Charmap))) == NULL)
 			{
 				fatalerror("Not enough memory for charmap");
 			}
@@ -110,7 +110,7 @@
 			if(input_length > strlen(charmap -> input[i]))
 			{
 				memcpy(temp1i, charmap -> input[i], CHARMAPLENGTH + 1);
-				memcpy(charmap -> input[i], input, CHARMAPLENGTH + 1);
+				memcpy(charmap -> input[i], input, input_length);
 				temp1o = charmap -> output[i];
 				charmap -> output[i] = output;
 				i++;
@@ -133,7 +133,7 @@
 	}
 	else
 	{
-		memcpy(charmap -> input[charmap -> count], input, CHARMAPLENGTH + 1);
+		memcpy(charmap -> input[charmap -> count], input, input_length);
 		charmap -> output[charmap -> count] = output;
 	}
 	return ++charmap -> count;
@@ -157,7 +157,6 @@
 		charmap = &globalCharmap;
 	}
 
-	length = 0;
 	input_temp = *input;
 	if((buffer = (char *) malloc(strlen(*input))) == NULL)
 	{