[gimp/gimp-2-6] SGI: cast allocation calculations



commit 88dfad9dc8bd9a20b46b1c3824634c969ef43986
Author: Nils Philippsen <nils redhat com>
Date:   Mon Dec 7 16:21:44 2009 +0100

    SGI: cast allocation calculations
    
    In order to avoid overflows when calculating needed memory, cast the
    first variable used into a large enough type so the whole calculation is
    done in that type.
    (cherry picked from commit 838be627be38d3ff25fddf7af16f0c98ddf4cc04)

 plug-ins/file-sgi/sgi.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/plug-ins/file-sgi/sgi.c b/plug-ins/file-sgi/sgi.c
index 60f7832..2c1be43 100644
--- a/plug-ins/file-sgi/sgi.c
+++ b/plug-ins/file-sgi/sgi.c
@@ -421,14 +421,14 @@ load_image (const gchar  *filename,
    */
 
   tile_height = gimp_tile_height ();
-  pixel       = g_new (guchar, tile_height * sgip->xsize * bytes);
+  pixel       = g_new (guchar, ((gsize) tile_height) * sgip->xsize * bytes);
   pixels      = g_new (guchar *, tile_height);
 
   for (i = 0; i < tile_height; i ++)
     pixels[i] = pixel + sgip->xsize * bytes * i;
 
   rows    = g_new (unsigned short *, sgip->zsize);
-  rows[0] = g_new (unsigned short, sgip->xsize * sgip->zsize);
+  rows[0] = g_new (unsigned short, ((gsize) sgip->xsize) * sgip->zsize);
 
   for (i = 1; i < sgip->zsize; i ++)
     rows[i] = rows[0] + i * sgip->xsize;
@@ -581,14 +581,14 @@ save_image (const gchar  *filename,
    */
 
   tile_height = gimp_tile_height ();
-  pixel       = g_new (guchar, tile_height * drawable->width * zsize);
+  pixel       = g_new (guchar, ((gsize) tile_height) * drawable->width * zsize);
   pixels      = g_new (guchar *, tile_height);
 
   for (i = 0; i < tile_height; i ++)
     pixels[i]= pixel + drawable->width * zsize * i;
 
   rows    = g_new (gushort *, sgip->zsize);
-  rows[0] = g_new (gushort, sgip->xsize * sgip->zsize);
+  rows[0] = g_new (gushort, ((gsize) sgip->xsize) * sgip->zsize);
 
   for (i = 1; i < sgip->zsize; i ++)
     rows[i] = rows[0] + i * sgip->xsize;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]