Skip to content

Commit d113624

Browse files
committed
Fix bug not taking into account that realloc may move memory.
1 parent 773b22c commit d113624

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

memory.c

+5-6
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ init_memory (struct pdp10_memory *memory)
5555
memory->current_address = 0;
5656
}
5757

58-
static void
58+
static struct pdp10_area *
5959
insert_area (struct pdp10_memory *memory, int i)
6060
{
6161
memory->areas++;
@@ -68,6 +68,7 @@ insert_area (struct pdp10_memory *memory, int i)
6868

6969
memmove (&memory->area[i+1], &memory->area[i],
7070
(memory->areas - i - 1) * sizeof (struct pdp10_area));
71+
return &memory->area[i];
7172
}
7273

7374
int
@@ -103,9 +104,7 @@ add_memory (struct pdp10_memory *memory, int address, int length, word_t *data)
103104
return 0;
104105
}
105106

106-
insert_area (memory, i);
107-
108-
area = &memory->area[i];
107+
area = insert_area (memory, i);
109108
area->start = address;
110109
area->end = address + length;
111110
area->flags = 0;
@@ -179,7 +178,7 @@ purify_memory (struct pdp10_memory *memory, int address, int length)
179178
if (area->start < i)
180179
{
181180
/* Impure area needs to split off first part. */
182-
insert_area (memory, area - memory->area);
181+
area = insert_area (memory, area - memory->area);
183182
area->end = i;
184183
data = area->data + area->end - area->start;
185184

@@ -194,7 +193,7 @@ purify_memory (struct pdp10_memory *memory, int address, int length)
194193
if (area->end > end)
195194
{
196195
/* Impure area needs to split off last part. */
197-
insert_area (memory, area - memory->area);
196+
area = insert_area (memory, area - memory->area);
198197
area->end = i;
199198
area->flags |= MEMORY_PURE;
200199

0 commit comments

Comments
 (0)