Browse Source

Fixed off by one errors…

Thomas Buck 12 years ago
parent
commit
9b9daf195d
1 changed files with 5 additions and 4 deletions
  1. 5
    4
      HardwareEmulator/mem.c

+ 5
- 4
HardwareEmulator/mem.c View File

19
 	char *newMem, *oldMem = mem;
19
 	char *newMem, *oldMem = mem;
20
 	int i;
20
 	int i;
21
 
21
 
22
+	frameCount++;
23
+
22
 	if (oldMem != NULL) {
24
 	if (oldMem != NULL) {
23
 		newMem = (char *)malloc(65 * frameCount);
25
 		newMem = (char *)malloc(65 * frameCount);
24
 		if (newMem == NULL) {
26
 		if (newMem == NULL) {
25
 			return 1;
27
 			return 1;
26
 		}
28
 		}
27
-		memcpy(newMem, oldMem, 65 * frameCount); // Copy old frames
29
+		memcpy(newMem, oldMem, 65 * (frameCount - 1)); // Copy old frames
28
 		free(oldMem);
30
 		free(oldMem);
29
 	} else {
31
 	} else {
30
 		// oldMem == NULL
32
 		// oldMem == NULL
31
-		frameCount = 0;
33
+		frameCount = 1;
32
 		newMem = (char *)malloc(65);
34
 		newMem = (char *)malloc(65);
33
 		if (newMem == NULL) {
35
 		if (newMem == NULL) {
34
 			return 1;
36
 			return 1;
35
 		}
37
 		}
36
 	}
38
 	}
37
 
39
 
38
-	memcpy((newMem + (65 * frameCount)), frame, 65); // Add new frame
40
+	memcpy((newMem + (65 * (frameCount - 1))), frame, 65); // Add new frame
39
 
41
 
40
-	frameCount++;
41
 	mem = newMem;
42
 	mem = newMem;
42
 	return 0;
43
 	return 0;
43
 }
44
 }

Loading…
Cancel
Save