This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository legacy-imlib2.

View the commit online.

commit 1b8cf498e57a45548c3f90ef01c642de8fdbdd43
Author: NRK <[email protected]>
AuthorDate: Sun May 8 11:26:37 2022 +0600

    check for alloc failures some more
---
 src/lib/grad.c      |  6 +++---
 src/lib/scale.c     |  6 ++++++
 src/lib/updates.c   |  7 +++++++
 src/lib/x11_color.c | 28 ++++++++++++++++++++++++++--
 4 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/src/lib/grad.c b/src/lib/grad.c
index f2be7aa..22c1295 100644
--- a/src/lib/grad.c
+++ b/src/lib/grad.c
@@ -19,10 +19,10 @@
 ImlibRange         *
 __imlib_CreateRange(void)
 {
-   ImlibRange         *rg = NULL;
+   ImlibRange         *rg;
+
+   rg = calloc(1, sizeof(ImlibRange));
 
-   rg = malloc(sizeof(ImlibRange));
-   rg->color = NULL;
    return rg;
 }
 
diff --git a/src/lib/scale.c b/src/lib/scale.c
index 1e4cc68..a2dbbad 100644
--- a/src/lib/scale.c
+++ b/src/lib/scale.c
@@ -36,6 +36,8 @@ __imlib_CalcYPoints(uint32_t * src, int sw, int sh, int dh, int b1, int b2)
      }
 
    p = malloc((dh + 1) * sizeof(uint32_t *));
+   if (!p)
+      return NULL;
 
    val = MIN(sh, dh);
    inc = b1 + b2;
@@ -94,6 +96,8 @@ __imlib_CalcXPoints(int sw, int dw, int b1, int b2)
      }
 
    p = malloc((dw + 1) * sizeof(int));
+   if (!p)
+      return NULL;
 
    val = MIN(sw, dw);
    inc = b1 + b2;
@@ -152,6 +156,8 @@ __imlib_CalcApoints(int s, int d, int b1, int b2, int up)
      }
 
    p = malloc(d * sizeof(int));
+   if (!p)
+      return NULL;
 
    val = MIN(s, d);
    inc = b1 + b2;
diff --git a/src/lib/updates.c b/src/lib/updates.c
index ba7ca09..527c823 100644
--- a/src/lib/updates.c
+++ b/src/lib/updates.c
@@ -39,6 +39,8 @@ __imlib_MergeUpdate(ImlibUpdate * u, int w, int h, int hgapmax)
    if (h & TM)
       th++;
    t = calloc(tw * th, sizeof(struct _tile));
+   if (!t)
+      return NULL;
    /* fill in all tiles */
    for (uu = u; uu; uu = uu->next)
      {
@@ -51,6 +53,11 @@ __imlib_MergeUpdate(ImlibUpdate * u, int w, int h, int hgapmax)
      }
    /* scan each line - if > hgapmax gaps between tiles, then fill smallest */
    gaps = malloc(tw * sizeof(int));
+   if (!gaps)
+     {
+        free(t);
+        return NULL;
+     }
    for (y = 0; y < th; y++)
      {
         int                 hgaps = 0, start = -1, min;
diff --git a/src/lib/x11_color.c b/src/lib/x11_color.c
index 539b725..6531317 100644
--- a/src/lib/x11_color.c
+++ b/src/lib/x11_color.c
@@ -82,6 +82,8 @@ __imlib_AllocColors332(Display * d, Colormap cmap, Visual * v)
    sig_mask <<= (16 - v->bits_per_rgb);
    i = 0;
    color_lut = malloc(256 * sizeof(uint8_t));
+   if (!color_lut)
+      return NULL;
    for (r = 0; r < 8; r++)
      {
         for (g = 0; g < 8; g++)
@@ -138,6 +140,8 @@ __imlib_AllocColors666(Display * d, Colormap cmap, Visual * v)
    sig_mask <<= (16 - v->bits_per_rgb);
    i = 0;
    color_lut = malloc(256 * sizeof(uint8_t));
+   if (!color_lut)
+      return NULL;
    for (r = 0; r < 6; r++)
      {
         for (g = 0; g < 6; g++)
@@ -194,6 +198,8 @@ __imlib_AllocColors232(Display * d, Colormap cmap, Visual * v)
    sig_mask <<= (16 - v->bits_per_rgb);
    i = 0;
    color_lut = malloc(128 * sizeof(uint8_t));
+   if (!color_lut)
+      return NULL;
    for (r = 0; r < 4; r++)
      {
         for (g = 0; g < 8; g++)
@@ -250,6 +256,8 @@ __imlib_AllocColors222(Display * d, Colormap cmap, Visual * v)
    sig_mask <<= (16 - v->bits_per_rgb);
    i = 0;
    color_lut = malloc(64 * sizeof(uint8_t));
+   if (!color_lut)
+      return NULL;
    for (r = 0; r < 4; r++)
      {
         for (g = 0; g < 4; g++)
@@ -306,6 +314,8 @@ __imlib_AllocColors221(Display * d, Colormap cmap, Visual * v)
    sig_mask <<= (16 - v->bits_per_rgb);
    i = 0;
    color_lut = malloc(32 * sizeof(uint8_t));
+   if (!color_lut)
+      return NULL;
    for (r = 0; r < 4; r++)
      {
         for (g = 0; g < 4; g++)
@@ -363,6 +373,8 @@ __imlib_AllocColors121(Display * d, Colormap cmap, Visual * v)
    sig_mask <<= (16 - v->bits_per_rgb);
    i = 0;
    color_lut = malloc(16 * sizeof(uint8_t));
+   if (!color_lut)
+      return NULL;
    for (r = 0; r < 2; r++)
      {
         for (g = 0; g < 4; g++)
@@ -421,6 +433,8 @@ __imlib_AllocColors111(Display * d, Colormap cmap, Visual * v)
    sig_mask <<= (16 - v->bits_per_rgb);
    i = 0;
    color_lut = malloc(8 * sizeof(uint8_t));
+   if (!color_lut)
+      return NULL;
    for (r = 0; r < 2; r++)
      {
         for (g = 0; g < 2; g++)
@@ -475,15 +489,25 @@ __imlib_AllocColors1(Display * d, Colormap cmap, Visual * v)
    uint8_t            *color_lut;
 
    color_lut = malloc(2 * sizeof(uint8_t));
+   if (!color_lut)
+      return NULL;
    xcl.red = (unsigned short)(0x0000);
    xcl.green = (unsigned short)(0x0000);
    xcl.blue = (unsigned short)(0x0000);
-   XAllocColor(d, cmap, &xcl);
+   if (!XAllocColor(d, cmap, &xcl))
+     {
+        free(color_lut);
+        return NULL;
+     }
    color_lut[0] = xcl.pixel;
    xcl.red = (unsigned short)(0xffff);
    xcl.green = (unsigned short)(0xffff);
    xcl.blue = (unsigned short)(0xffff);
-   XAllocColor(d, cmap, &xcl);
+   if (!XAllocColor(d, cmap, &xcl))
+     {
+        free(color_lut);
+        return NULL;
+     }
    color_lut[1] = xcl.pixel;
    return color_lut;
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to