From d8f42fb418eb16aefea3ed147642af14cbf311f0 Mon Sep 17 00:00:00 2001 From: sam Date: Mon, 13 Oct 2008 01:15:06 +0000 Subject: [PATCH] libpipi: replace large stack buffer allocations with malloc(). git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2941 92316355-f0b4-4df1-b90c-862c8a59935f --- pipi/codec/oric.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pipi/codec/oric.c b/pipi/codec/oric.c index 28c4be4..d31d6ca 100644 --- a/pipi/codec/oric.c +++ b/pipi/codec/oric.c @@ -50,14 +50,18 @@ pipi_image_t *pipi_load_oric(char const *name) 0xff, 0xff, 0xff, 0xff, }; - uint8_t screen[WIDTH * HEIGHT / 6]; pipi_image_t *img; pipi_pixels_t *p; - uint8_t *data; + uint8_t *screen, *data; int x, y, i; + screen = malloc(WIDTH * HEIGHT / 6); + if(read_screen(name, screen) < 0) + { + free(screen); return NULL; + } img = pipi_new(WIDTH, HEIGHT); p = pipi_getpixels(img, PIPI_PIXELS_RGBA_C); @@ -99,6 +103,8 @@ pipi_image_t *pipi_load_oric(char const *name) } } + free(screen); + img->codec_priv = NULL; img->wrap = 0; @@ -109,10 +115,10 @@ pipi_image_t *pipi_load_oric(char const *name) int pipi_save_oric(pipi_image_t *img, char const *name) { - uint8_t screen[WIDTH * HEIGHT / 6]; pipi_image_t *tmp = NULL; pipi_pixels_t *p; float *data; + uint8_t *screen; FILE *fp; size_t len; @@ -140,13 +146,19 @@ int pipi_save_oric(pipi_image_t *img, char const *name) else p = pipi_getpixels(img, PIPI_PIXELS_RGBA_F); data = p->pixels; + screen = malloc(WIDTH * HEIGHT / 6); write_screen(data, screen); if(tmp) + { + free(screen); pipi_free(tmp); + } fwrite(screen, 1, WIDTH * HEIGHT / 6, fp); fclose(fp); + free(screen); + return 0; }