mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-29 17:39:09 +00:00
(svn r5394) Allocate a small, fixed-size array on the stack instead of malloc()ing it
This commit is contained in:
@@ -393,15 +393,15 @@ static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *user
|
|||||||
success = fwrite(palette, 256 * sizeof(*palette), 1, f) == 1;
|
success = fwrite(palette, 256 * sizeof(*palette), 1, f) == 1;
|
||||||
} else {
|
} else {
|
||||||
/* If the palette is word-aligned, copy it to a temporary byte array */
|
/* If the palette is word-aligned, copy it to a temporary byte array */
|
||||||
byte *tmp = malloc(256 * 3);
|
byte tmp[256 * 3];
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
tmp[i * 3 + 0] = palette[i].r;
|
tmp[i * 3 + 0] = palette[i].r;
|
||||||
tmp[i * 3 + 1] = palette[i].g;
|
tmp[i * 3 + 1] = palette[i].g;
|
||||||
tmp[i * 3 + 2] = palette[i].b;
|
tmp[i * 3 + 2] = palette[i].b;
|
||||||
}
|
}
|
||||||
success = fwrite(tmp, 256 * 3, 1, f) == 1;
|
success = fwrite(tmp, sizeof(tmp), 1, f) == 1;
|
||||||
free(tmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
Reference in New Issue
Block a user