[X2Go-Commits] [nx-libs] 103/219: compext/Png.c: simplify srcBuf allocation

git-admin at x2go.org git-admin at x2go.org
Sat Sep 28 12:10:31 CEST 2019


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

x2go pushed a commit to branch 3.6.x
in repository nx-libs.

commit e440e722d8639411722d8a2499df46fe18c45f31
Author: Ulrich Sibiller <uli42 at gmx.de>
Date:   Thu Jun 20 19:53:39 2019 +0200

    compext/Png.c: simplify srcBuf allocation
---
 nx-X11/programs/Xserver/hw/nxagent/compext/Png.c | 43 +++++++-----------------
 1 file changed, 13 insertions(+), 30 deletions(-)

diff --git a/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c b/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c
index e80f3879d..77a1941ea 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c
@@ -481,47 +481,23 @@ char *PngCompressData(XImage *image, int *compressed_size)
     return NULL;
   }
 
+  int count;
   if (color_type == PNG_COLOR_TYPE_PALETTE)
   {
-    srcBuf = (CARD8 *) malloc(w * sizeof(CARD8));
-
-    if (srcBuf == NULL)
-    {
-      #ifdef PANIC
-      fprintf(stderr, "******PngCompressData: PANIC! Cannot allocate [%d] bytes.\n",
-                  (int) (w * sizeof(CARD8)));
-      #endif
-
-      free(image_index);
-
-      return NULL;
-    }
-
-    /*
-     * TODO: Be sure the padded bytes are cleaned.
-     * It would be better to set to zero the bytes
-     * that are not aligned to the word boundary
-     * at the end of the procedure.
-     */
-
-    memset(srcBuf, 0, w * sizeof(CARD8));
+    count = w;
   }
   else
   {
-    srcBuf = (CARD8 *) malloc(w * 3 * sizeof(CARD8));
-
-    /*
-     * TODO: See above.
-     */
-
-    memset(srcBuf, 0, w * 3 * sizeof(CARD8));
+    count = 3 * w;
   }
 
+  srcBuf = (CARD8 *) calloc(count, sizeof(CARD8));
+
   if (srcBuf == NULL)
   {
     #ifdef PANIC
     fprintf(stderr, "******PngCompressData: PANIC! Cannot allocate [%d] bytes.\n",
-                w * 3);
+                  (int) (count * sizeof(CARD8)));
     #endif
 
     free(pngCompBuf);
@@ -530,6 +506,13 @@ char *PngCompressData(XImage *image, int *compressed_size)
     return NULL;
   }
 
+  /*
+   * TODO: Be sure the padded bytes are cleaned.
+   * It would be better to set to zero the bytes
+   * that are not aligned to the word boundary
+   * at the end of the procedure.
+   */
+
   for (dy = 0; dy < h; dy++)
   {
     if (color_type == PNG_COLOR_TYPE_RGB)

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/nx-libs.git


More information about the x2go-commits mailing list