Skip to content

Commit eb4d5f8

Browse files
committed
Work around clang-10 issue where the pixel and undo buffers were
overlapping by 33 bytes.
1 parent 2c3942c commit eb4d5f8

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

sprite.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ typedef struct pixel {
4141
int color;
4242
} pixel_t;
4343
static pixel_t pixel[32][32];
44-
static pixel_t undo[32][32];
4544

4645
static int
4746
switch_color(int color)
@@ -232,21 +231,21 @@ change_color(int y, int x, int color)
232231
}
233232

234233
static void
235-
do_undo(void)
234+
do_undo(int go)
236235
{
237-
pixel_t temp[32][32];
236+
static pixel_t temp[32][32], undo[32][32];
238237

239-
memset(&temp, 0, sizeof(temp));
238+
if (go) {
239+
memset(&temp, 0, sizeof(temp));
240240

241-
memmove(&temp, &pixel, sizeof(temp));
242-
memmove(&pixel, &undo, sizeof(pixel));
243-
memmove(&undo, &temp, sizeof(temp));
244-
}
241+
memmove(&temp, &pixel, sizeof(temp));
242+
memmove(&pixel, &undo, sizeof(pixel));
243+
memmove(&undo, &temp, sizeof(undo));
245244

246-
static void
247-
update_undo(void)
248-
{
245+
return;
246+
}
249247

248+
/* Otherwise, update the buffer */
250249
memmove(&undo, &pixel, sizeof(undo));
251250
}
252251

@@ -524,7 +523,7 @@ main_loop(void)
524523
switch ((c = getch())) {
525524
case '/':
526525
if ((lock = !lock)) {
527-
update_undo();
526+
do_undo(0);
528527
goto print;
529528
}
530529
break;
@@ -561,7 +560,7 @@ main_loop(void)
561560
goto print;
562561
break;
563562
case ' ':
564-
update_undo();
563+
do_undo(0);
565564
print:
566565
pixel[y - 4][x - 32].color = color;
567566
dirty = 1;
@@ -574,7 +573,7 @@ main_loop(void)
574573
break;
575574
case 'D':
576575
case 'd':
577-
update_undo();
576+
do_undo(0);
578577
pixel[y - 4][x - 32].color = -1;
579578
dirty = 1;
580579
break;
@@ -584,7 +583,7 @@ main_loop(void)
584583
break;
585584
case 'F':
586585
case 'f':
587-
update_undo();
586+
do_undo(0);
588587
fill_region(y, x, color, pixel[y - 4][x - 32].color);
589588
dirty = 1;
590589
break;
@@ -601,7 +600,7 @@ main_loop(void)
601600
break;
602601
case 'U':
603602
case 'u':
604-
do_undo();
603+
do_undo(1);
605604
}
606605

607606
draw_screen(y, x, color);
@@ -652,6 +651,9 @@ main(int argc, char *argv[])
652651

653652
draw_transparency();
654653

654+
/* Set up undo structures */
655+
do_undo(0);
656+
655657
if (argc == 1)
656658
file_open(*argv);
657659

0 commit comments

Comments
 (0)