changeset 796:41f73c76b978

Fix some memory issues
author =?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
date Sun, 26 Jul 2015 11:00:25 -0700
parents bce97fc0bb8a
children 65181c3ee560
files config.c io.c m68k_core.c
diffstat 3 files changed, 13 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/config.c	Sun Jul 26 10:59:41 2015 -0700
+++ b/config.c	Sun Jul 26 11:00:25 2015 -0700
@@ -48,11 +48,11 @@
 		curline = strip_ws(curline);
 		int len = strlen(curline);
 		if (!len) {
-			*line++;
+			*line = *line + 1;
 			continue;
 		}
 		if (curline[0] == '#') {
-			*line++;
+			*line = *line + 1;
 			continue;
 		}
 		if (curline[0] == '}') {
@@ -67,7 +67,7 @@
 		if (*end == '{') {
 			*end = 0;
 			curline = strip_ws(curline);
-			*line++;
+			*line = *line + 1;
 			head = tern_insert_node(head, curline, parse_config_int(state, 1, line));
 		} else {
 			char * val = strip_ws(split_keyval(curline));
@@ -77,7 +77,7 @@
 			} else {
 				fprintf(stderr, "Key %s is missing a value on line %d\n", key, *line);
 			}
-			*line++;
+			*line = *line + 1;
 		}
 	}
 	return head;
@@ -100,10 +100,12 @@
 	if (!config_size) {
 		goto config_empty;
 	}
-	char * config_data = malloc(config_size);
+	char * config_data = malloc(config_size+1);
 	if (fread(config_data, 1, config_size, config_file) != config_size) {
 		goto config_read_fail;
 	}
+	config_data[config_size] = '\0';
+
 	ret = parse_config(config_data);
 config_read_fail:
 	free(config_data);
--- a/io.c	Sun Jul 26 10:59:41 2015 -0700
+++ b/io.c	Sun Jul 26 11:00:25 2015 -0700
@@ -340,7 +340,7 @@
 int parse_binding_target(char * target, tern_node * padbuttons, int * ui_out, int * padnum_out, int * padbutton_out)
 {
 	int gpadslen = strlen("gamepads.");
-	if (!memcmp(target, "gamepads.", gpadslen)) {
+	if (!strncmp(target, "gamepads.", gpadslen)) {
 		if (target[gpadslen] >= '1' && target[gpadslen] <= '8') {
 			int padnum = target[gpadslen] - '0';
 			int button = tern_find_int(padbuttons, target + gpadslen + 1, 0);
@@ -358,7 +358,7 @@
 		} else {
 			fprintf(stderr, "Gamepad mapping string '%s' refers to an invalid gamepad number %c\n", target, target[gpadslen]);
 		}
-	} else if(!memcmp(target, "ui.", strlen("ui."))) {
+	} else if(!strncmp(target, "ui.", strlen("ui."))) {
 		*padbutton_out = 0;
 		if (!strcmp(target + 3, "vdp_debug_mode")) {
 			*ui_out = UI_DEBUG_MODE_INC;
@@ -368,7 +368,7 @@
 			*ui_out = UI_ENTER_DEBUGGER;
 		} else if(!strcmp(target + 3, "save_state")) {
 			*ui_out = UI_SAVE_STATE;
-		} else if(!memcmp(target + 3, "set_speed.", strlen("set_speed."))) {
+		} else if(!strncmp(target + 3, "set_speed.", strlen("set_speed."))) {
 			*ui_out = UI_SET_SPEED;
 			*padbutton_out = atoi(target + 3 + strlen("set_speed."));
 		} else if(!strcmp(target + 3, "next_speed")) {
--- a/m68k_core.c	Sun Jul 26 10:59:41 2015 -0700
+++ b/m68k_core.c	Sun Jul 26 11:00:25 2015 -0700
@@ -1004,8 +1004,9 @@
 
 m68k_context * init_68k_context(m68k_options * opts)
 {
-	m68k_context * context = malloc(sizeof(m68k_context) + ram_size(&opts->gen) / (1 << opts->gen.ram_flags_shift) / 8);
-	memset(context, 0, sizeof(m68k_context));
+	size_t ctx_size = sizeof(m68k_context) + ram_size(&opts->gen) / (1 << opts->gen.ram_flags_shift) / 8;
+	m68k_context * context = malloc(ctx_size);
+	memset(context, 0, ctx_size);
 	context->native_code_map = opts->gen.native_code_map;
 	context->options = opts;
 	context->int_cycle = CYCLE_NEVER;