freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] master 67ac6c0: [graph] Use size_t in memory allocatio


From: Alexei Podtelezhnikov
Subject: [freetype2-demos] master 67ac6c0: [graph] Use size_t in memory allocations, handle zero-size bitmap.
Date: Tue, 26 May 2020 14:00:28 -0400 (EDT)

branch: master
commit 67ac6c0360d43f596647479e4494563882e9b951
Author: Alexei Podtelezhnikov <address@hidden>
Commit: Alexei Podtelezhnikov <address@hidden>

    [graph] Use size_t in memory allocations, handle zero-size bitmap.
    
    * graph/grblit.c, graph/grdevice.c, graph/grdevice.h,
    graph/x11/grx11.c: s/unsigned long/size_t/
    * graph/grobjs.h: Ditto and inclide <stdlib.h>
    * graph/grobjs.c (grAlloc): Ditto.
    (grNewBitmap): Handle zero height or width.
---
 ChangeLog         | 10 ++++++++++
 graph/grblit.c    |  5 ++---
 graph/grdevice.c  |  1 -
 graph/grdevice.h  |  4 ++--
 graph/grobjs.c    |  9 ++++-----
 graph/grobjs.h    |  4 +++-
 graph/x11/grx11.c |  4 ++--
 7 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index acaf39a..471b515 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2020-05-25  Alexei Podtelezhnikov  <address@hidden>
 
+       [graph] Use size_t in memory allocations, handle zero-size bitmap.
+
+       * graph/grblit.c, graph/grdevice.c, graph/grdevice.h,
+       graph/x11/grx11.c: s/unsigned long/size_t/
+       * graph/grobjs.h: Ditto and inclide <stdlib.h>
+       * graph/grobjs.c (grAlloc): Ditto.
+       (grNewBitmap): Handle zero height or width.
+
+2020-05-25  Alexei Podtelezhnikov  <address@hidden>
+
        * graph/grfill.c (grFillRect): Small bug.
 
 2020-05-21  Alexei Podtelezhnikov  <address@hidden>
diff --git a/graph/grblit.c b/graph/grblit.c
index 435025c..3f8e02e 100644
--- a/graph/grblit.c
+++ b/graph/grblit.c
@@ -575,7 +575,7 @@
       int          i;
       const byte*  table;
 
-      table = (const byte*)grAlloc( (unsigned long)( 3 * num_grays - 1 ) *
+      table = (const byte*)grAlloc( (size_t)( 3 * num_grays - 1 ) *
                                     sizeof ( byte ) );
       if (!table) return 0;
 
@@ -673,8 +673,7 @@
       const byte*  table;
       int          n;
 
-      table = (const byte*)grAlloc( (unsigned long)source_grays *
-                                    sizeof ( byte ) );
+      table = (const byte*)grAlloc( (size_t)source_grays * sizeof ( byte ) );
       if (!table)
         return 0;
 
diff --git a/graph/grdevice.c b/graph/grdevice.c
index 26d7b7a..a0dc840 100644
--- a/graph/grdevice.c
+++ b/graph/grdevice.c
@@ -1,6 +1,5 @@
 #include "grobjs.h"
 #include "grdevice.h"
-#include <stdlib.h>
 #include <string.h>
 
   grDeviceChain*  gr_device_chain;
diff --git a/graph/grdevice.h b/graph/grdevice.h
index d0df8e0..7e10777 100644
--- a/graph/grdevice.h
+++ b/graph/grdevice.h
@@ -107,8 +107,8 @@
 
   struct grDevice_
   {
-    unsigned int  surface_objsize;
-    const char*   device_name;  /* name of device                 */
+    size_t       surface_objsize;
+    const char*  device_name;  /* name of device                 */
 
     grDeviceInitFunc        init;
     grDeviceDoneFunc        done;
diff --git a/graph/grobjs.c b/graph/grobjs.c
index e747df4..477716e 100644
--- a/graph/grobjs.c
+++ b/graph/grobjs.c
@@ -1,5 +1,4 @@
 #include "grobjs.h"
-#include <stdlib.h>
 #include <string.h>
 
   int  grError = 0;
@@ -77,7 +76,7 @@
   ********************************************************************/
 
   unsigned char*
-  grAlloc( unsigned long  size )
+  grAlloc( size_t  size )
   {
     unsigned char*  p;
 
@@ -198,7 +197,7 @@
 
     if ( !bit->buffer )
     {
-       bit->buffer = grAlloc( (unsigned long)( pitch * height ) );
+       bit->buffer = grAlloc( (size_t)pitch * (size_t)height );
        if (!bit->buffer) goto Fail;
     }
     else  /* resize */
@@ -207,8 +206,8 @@
 
 
        buffer = (unsigned char*)realloc( bit->buffer,
-                        (unsigned long)( pitch * height ) );
-       if ( buffer )
+                                         (size_t)pitch * (size_t)height );
+       if ( buffer || !pitch || !height )
          bit->buffer = buffer;
        else
          goto Fail;
diff --git a/graph/grobjs.h b/graph/grobjs.h
index b8fa9d9..4b72287 100644
--- a/graph/grobjs.h
+++ b/graph/grobjs.h
@@ -15,6 +15,8 @@
 #ifndef GROBJS_H_
 #define GROBJS_H_
 
+#include <stdlib.h>
+
 #include "graph.h"
 #include "grconfig.h"
 #include "grtypes.h"
@@ -165,7 +167,7 @@
   ********************************************************************/
 
   extern unsigned char*
-  grAlloc( unsigned long  size );
+  grAlloc( size_t  size );
 
 
  /********************************************************************
diff --git a/graph/x11/grx11.c b/graph/x11/grx11.c
index 02b7ad3..8788c50 100644
--- a/graph/x11/grx11.c
+++ b/graph/x11/grx11.c
@@ -1339,8 +1339,8 @@ typedef  unsigned long   uint32;
       pximage->rows   = bitmap->rows;
     }
 
-    pximage->buffer = (unsigned char*)grAlloc(
-                        (unsigned long)( pximage->pitch * pximage->rows ) );
+    pximage->buffer = (unsigned char*)grAlloc( (size_t)pximage->pitch *
+                                               (size_t)pximage->rows );
     if ( !pximage->buffer )
       return 0;
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]