[gs-commits] ghostpdl branch, master, updated. jbig2dec-0.14-2004-g8636935

[email protected] (Julian Smith) Fri, 29 Nov 2019 15:14:59 +0000 (UTC)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
The ghostpdl branch, master has been updated
       via  8636935ac086f56464f0541ed735f1016f2c3895 (commit)
       via  a3f284624a68dcb1ecb72dcf307b42d194e78de1 (commit)
       via  ff02f8741f71830e7a4795645680a16b9d7ae106 (commit)
       via  f977255de00bb71f5c2627b8692912bb3263ee48 (commit)
       via  f877f5bc792206085f9edf4143983d4156fb3ae5 (commit)
       via  39286afa21126c193fcd0f3ccc0800f7c0662ed0 (commit)
       via  1c899fc1100f21f6e24096375e2daac26b23f33b (commit)
       via  adbf399b79b3e6b645e98acd53f42f9fd5ca9174 (commit)
       via  1d04fe90a4c3b82e1286a1b341cdb89a96625715 (commit)
       via  fbd78a0467afb2c66a41d55ee9b3aee0a7a01d7b (commit)
      from  a537e5bd4252abdbdc3f90dfdce8dc9fb621b38d (commit)

----------------------------------------------------------------------
commit 8636935ac086f56464f0541ed735f1016f2c3895
Author: Julian Smith <[email protected]>
Date:   Fri Nov 29 14:40:47 2019 +0000

    Coverity 94659: removed cp_num - was allocated but never actually used.

diff --git a/contrib/opvp/gdevopvp.c b/contrib/opvp/gdevopvp.c
index ccbd63b..115b3f2 100644
--- a/contrib/opvp/gdevopvp.c
+++ b/contrib/opvp/gdevopvp.c
@@ -4835,7 +4835,6 @@ opvp_vector_dopath(
     int i;
     int pop = 0;
     int npoints = 0;
-    int *cp_num = NULL;
     _fPoint *points = NULL;
     opvp_point_t *opvp_p = NULL;
     _fPoint current;
@@ -4914,11 +4913,6 @@ opvp_vector_dopath(
                 break;
             case gs_pe_curveto:
                 /* npoints */
-                if (!cp_num)
-                cp_num = calloc(sizeof(int), 2);
-                cp_num[0] = npoints;
-                cp_num[1] = 0;
-
                 /* call BezierPath */
                 if (apiEntry->opvpBezierPath) {
                     r = apiEntry->opvpBezierPath(
@@ -4940,7 +4934,6 @@ opvp_vector_dopath(
 
             /* reset */
             npoints = 1;
-            if (cp_num) free(cp_num), cp_num = NULL;
             points = realloc(points, sizeof(_fPoint));
             points[0] = current;
 #endif
@@ -5068,7 +5061,6 @@ opvp_vector_dopath(
 #ifdef  OPVP_OPT_MULTI_PATH
     if (points) free(points);
     if (opvp_p) free(opvp_p);
-    if (cp_num) free(cp_num);
 #endif
     return ecode;
 }

----------------------------------------------------------------------
commit a3f284624a68dcb1ecb72dcf307b42d194e78de1
Author: Julian Smith <[email protected]>
Date:   Fri Nov 29 14:35:25 2019 +0000

    Coverity 94653: fixed incorrect if() that was logically dead code.

diff --git a/contrib/lips4/gdevl4v.c b/contrib/lips4/gdevl4v.c
index cdfba93..b0c204b 100644
--- a/contrib/lips4/gdevl4v.c
+++ b/contrib/lips4/gdevl4v.c
@@ -1396,12 +1396,12 @@ lips4v_endpath(gx_device_vector * vdev, gx_path_type_t type)
     lputs(s, "P)");
     sputc(s, LIPS_IS2);
     if (type & gx_path_type_rule) {
-        if (type & gx_path_type_winding_number) {
-            lputs(s, "}I1");
-            sputc(s, LIPS_IS2);
-        } else {
+        if (type & gx_path_type_even_odd) {
             lputs(s, "}I0");
             sputc(s, LIPS_IS2);
+        } else {
+            lputs(s, "}I1");
+            sputc(s, LIPS_IS2);
         }
     }
     if (type & gx_path_type_fill) {

----------------------------------------------------------------------
commit ff02f8741f71830e7a4795645680a16b9d7ae106
Author: Julian Smith <[email protected]>
Date:   Fri Nov 29 14:15:57 2019 +0000

    Coverity 94652: return error from opvp_image_plane_data() rather than segv.

diff --git a/contrib/opvp/gdevopvp.c b/contrib/opvp/gdevopvp.c
index 4a8ab00..ccbd63b 100644
--- a/contrib/opvp/gdevopvp.c
+++ b/contrib/opvp/gdevopvp.c
@@ -4028,6 +4028,10 @@ opvp_image_plane_data(
     if (buf) {
         /* Adjust image data gamma */
         pbe = (bbox_image_enum *)vinfo->bbox_info;
+        if (!pbe) {
+            ecode = gs_note_error(gs_error_invalidaccess);
+            goto end;
+        }
         tinfo = (gx_image_enum *)pbe->target_info;
         pgs = tinfo->pgs;
 
@@ -4382,14 +4386,15 @@ opvp_image_plane_data(
             apiEntry->opvpTransferDrawImage(printerContext,
                         raster_length * height, (void *)buf);
         }
-        if (buf) {
-            free(buf); /* free buffer */
-        }
     }
 
     vinfo->y += height;
     ecode = (vinfo->y >= vinfo->height);
 
+end:
+    if (buf) {
+        free(buf); /* free buffer */
+    }
     return ecode;
 }
 

----------------------------------------------------------------------
commit f977255de00bb71f5c2627b8692912bb3263ee48
Author: Julian Smith <[email protected]>
Date:   Fri Nov 29 12:40:02 2019 +0000

    Coverity 94645: added '/* Fall through. */ comments to switch statements.
    
    This should convince Coverity that the fall-through's are intentional.

diff --git a/contrib/lips4/gdevl4r.c b/contrib/lips4/gdevl4r.c
index d826fd4..01f9cf9 100644
--- a/contrib/lips4/gdevl4r.c
+++ b/contrib/lips4/gdevl4r.c
@@ -520,6 +520,7 @@ lips4_put_params(gx_device * pdev, gs_param_list * plist)
         default:
             ecode = code;
           pmediae:param_signal_error(plist, param_name, ecode);
+          /* Fall through. */
         case 1:
             pmedia.data = 0;
             break;

----------------------------------------------------------------------
commit f877f5bc792206085f9edf4143983d4156fb3ae5
Author: Julian Smith <[email protected]>
Date:   Fri Nov 29 12:38:10 2019 +0000

    Coverity 94638: added '/* Fall through. */ comments to switch statements.
    
    This should convince Coverity that the fall-through's are intentional.

diff --git a/contrib/gdevmd2k.c b/contrib/gdevmd2k.c
index 690f22b..8620277 100644
--- a/contrib/gdevmd2k.c
+++ b/contrib/gdevmd2k.c
@@ -539,12 +539,14 @@ alps_print_page(gx_device_printer *pdev, gp_file *prn_stream,
                 /* get a component of CMYK from raster data */
                 len = cmyk_to_bit(work, dp, len, c_comp);
                 dp = work;
+                /* Fall through. */
             case 1:
                 /* remove trailing 0s */
                 for( ; len > 0 && dp[len-1] == 0; len --);
                 break;
             case 32:
                 dp += c_comp;
+                /* Fall through. */
             case 8:
                 outP = work;
                 ep = error;

----------------------------------------------------------------------
commit 39286afa21126c193fcd0f3ccc0800f7c0662ed0
Author: Julian Smith <[email protected]>
Date:   Fri Nov 29 12:33:51 2019 +0000

    Coverity 94616: added '/* Fall through. */ comments to switch statements
    
    This should convince Coverity that the fall-through's are intentional.

diff --git a/contrib/gdevgdi.c b/contrib/gdevgdi.c
index b22b147..38181a9 100644
--- a/contrib/gdevgdi.c
+++ b/contrib/gdevgdi.c
@@ -484,12 +484,15 @@ unsigned long FrameTiffComp(unsigned char *pubDest,
     case 1:
       *TgtPtr++ = 0x00;
       ulret++;
+      /* Fall through. */
     case 2:
       *TgtPtr++ = 0x00;
       ulret++;
+      /* Fall through. */
     case 3:
       *TgtPtr++ = 0x00;
       ulret++;
+      /* Fall through. */
     default:
       break;
     }
@@ -500,10 +503,13 @@ unsigned long FrameTiffComp(unsigned char *pubDest,
     {
     case 1:
       ulret++;
+      /* Fall through. */
     case 2:
       ulret++;
+      /* Fall through. */
     case 3:
       ulret++;
+      /* Fall through. */
     default:
       break;
     }

----------------------------------------------------------------------
commit 1c899fc1100f21f6e24096375e2daac26b23f33b
Author: Julian Smith <[email protected]>
Date:   Fri Nov 29 12:30:57 2019 +0000

    Coverity 94608: added '/* Fall through. */ comments to switch statements.
    
    This should convince Coverity that the fall-through's are intentional.

diff --git a/contrib/lips4/gdevl4v.c b/contrib/lips4/gdevl4v.c
index eb4f31a..cdfba93 100644
--- a/contrib/lips4/gdevl4v.c
+++ b/contrib/lips4/gdevl4v.c
@@ -1640,6 +1640,7 @@ lips4v_put_params(gx_device * dev, gs_param_list * plist)
         default:
         ecode = code;
       casse:param_signal_error(plist, param_name, ecode);
+        /* Fall through. */
         case 1:
         break;
     }
@@ -1665,6 +1666,7 @@ lips4v_put_params(gx_device * dev, gs_param_list * plist)
         default:
         ecode = code;
       pmediae:param_signal_error(plist, param_name, ecode);
+        /* Fall through. */
         case 1:
         pmedia.data = 0;
         break;
@@ -1695,6 +1697,7 @@ lips4v_put_params(gx_device * dev, gs_param_list * plist)
         default:
         ecode = code;
       userne:param_signal_error(plist, param_name, ecode);
+        /* Fall through. */
         case 1:
         usern.data = 0;
         break;
@@ -1716,6 +1719,7 @@ lips4v_put_params(gx_device * dev, gs_param_list * plist)
         default:
         ecode = code;
       nupe:param_signal_error(plist, param_name, ecode);
+        /* Fall through. */
         case 1:
         break;
     }
@@ -1736,6 +1740,7 @@ lips4v_put_params(gx_device * dev, gs_param_list * plist)
         default:
         ecode = code;
       tden:param_signal_error(plist, param_name, ecode);
+        /* Fall through. */
         case 1:
         break;
     }
@@ -1771,6 +1776,7 @@ lips4v_put_params(gx_device * dev, gs_param_list * plist)
             }
             ecode = code;
             param_signal_error(plist, param_name, ecode);
+            /* Fall through. */
             case 1:
             break;
         }
@@ -1795,6 +1801,7 @@ lips4v_put_params(gx_device * dev, gs_param_list * plist)
         default:
         ecode = code;
       bppe:param_signal_error(plist, param_name, ecode);
+        /* Fall through. */
         case 1:
         break;
     }

----------------------------------------------------------------------
commit adbf399b79b3e6b645e98acd53f42f9fd5ca9174
Author: Julian Smith <[email protected]>
Date:   Fri Nov 29 12:10:19 2019 +0000

    Coverity 94601: avoid out-of-bounds access of gendata->dev->hoffset[] if newhead < 0.

diff --git a/contrib/gdevlx32.c b/contrib/gdevlx32.c
index 652668d..df17e24 100644
--- a/contrib/gdevlx32.c
+++ b/contrib/gdevlx32.c
@@ -1243,8 +1243,13 @@ finalizeheader(pagedata *gendata, int vskip, int newhead)
          */
         dir = (header[2] & 0x01 ? LEFT : RIGHT);
 
-        /* Retrieve the horizontal offset for the next stripe */
-        offs2 = gendata->dev->hoffset[newhead][gendata->direction];
+        /* Retrieve the horizontal offset for the next stripe. We don't do this
+        if newhead is negative, because otherwise we would be out of bounds in
+        gendata->dev->hoffset[]; offs2 isn't actually used in this case anyway.
+        */
+        if (newhead >= 0) {
+            offs2 = gendata->dev->hoffset[newhead][gendata->direction];
+        }
 
         /* Calculate the separation adjust in 1200ths of an inch */
         if(newhead == LEFT)
@@ -1263,7 +1268,9 @@ finalizeheader(pagedata *gendata, int vskip, int newhead)
         vskip *= gendata->yrmul;
 
         /* Calculate absolute starting position of new stripe */
-        nstartabs = newstart + offs2;
+        if (newhead >= 0) {
+            nstartabs = newstart + offs2;
+        }
 
         /* Calculate absolute ending position of this stripe
          * by summing (with proper sign) the starting position

----------------------------------------------------------------------
commit 1d04fe90a4c3b82e1286a1b341cdb89a96625715
Author: Julian Smith <[email protected]>
Date:   Fri Nov 29 11:41:05 2019 +0000

    Coverity 94490: check return codes in opvp_fill_mask().

diff --git a/contrib/opvp/gdevopvp.c b/contrib/opvp/gdevopvp.c
index 9dd1b79..4a8ab00 100644
--- a/contrib/opvp/gdevopvp.c
+++ b/contrib/opvp/gdevopvp.c
@@ -3582,13 +3582,17 @@ opvp_fill_mask(
     const gx_clip_path *pcpath)
 {
     if (vector) {
+        int code;
 #if GS_VERSION_MAJOR >= 8       /* for gs 8.15 */
-        gdev_vector_update_fill_color((gx_device_vector *)dev, NULL, pdcolor);
+        code = gdev_vector_update_fill_color((gx_device_vector *)dev, NULL, pdcolor);
 #else
-        gdev_vector_update_fill_color((gx_device_vector *)dev, pdcolor);
+        code = gdev_vector_update_fill_color((gx_device_vector *)dev, pdcolor);
 #endif
-        gdev_vector_update_clip_path((gx_device_vector *)dev, pcpath);
-        gdev_vector_update_log_op((gx_device_vector *)dev, lop);
+        if (code < 0)   return code;
+        code = gdev_vector_update_clip_path((gx_device_vector *)dev, pcpath);
+        if (code < 0)   return code;
+        code = gdev_vector_update_log_op((gx_device_vector *)dev, lop);
+        if (code < 0)   return code;
     }
 
     return gx_default_fill_mask(dev, data, data_x, raster, id,

----------------------------------------------------------------------
commit fbd78a0467afb2c66a41d55ee9b3aee0a7a01d7b
Author: Julian Smith <[email protected]>
Date:   Thu Nov 28 18:26:56 2019 +0000

    Coverity 94511: Use full range of frac when source is 8-bit.
    
    Essentially we use frac2byte() and byte2frac(), instead of frac2cv() and
    cv2frac(). This ensures we use full range of frac with the transfer fns.
    
    Note that this change is untested. It is based on observation and discussion
    between gs develpoers. This code has not been modified since initial import.

diff --git a/contrib/opvp/gdevopvp.c b/contrib/opvp/gdevopvp.c
index b49d507..9dd1b79 100644
--- a/contrib/opvp/gdevopvp.c
+++ b/contrib/opvp/gdevopvp.c
@@ -4340,20 +4340,16 @@ opvp_image_plane_data(
             for (i = 0; i < height; i++) {
                 ptr = buf + raster_length * i;
                 for (j = 0; j < vinfo->width; j++) {
-                    ptr[j*3] = min(255, frac2cv(gx_map_color_frac(pgs,
-                      cv2frac(ptr[j*3]), effective_transfer[0])));
-                    ptr[j*3+1] = min(255, frac2cv(gx_map_color_frac(pgs,
-                      cv2frac(ptr[j*3+1]), effective_transfer[1])));
-                    ptr[j*3+2] = min(255, frac2cv(gx_map_color_frac(pgs,
-                      cv2frac(ptr[j*3+2]), effective_transfer[2])));
+                    ptr[j*3+0] = frac2byte(gx_map_color_frac(pgs, byte2frac(ptr[j*3+0]), effective_transfer[0]));
+                    ptr[j*3+1] = frac2byte(gx_map_color_frac(pgs, byte2frac(ptr[j*3+1]), effective_transfer[1]));
+                    ptr[j*3+2] = frac2byte(gx_map_color_frac(pgs, byte2frac(ptr[j*3+2]), effective_transfer[2]));
                 }
             }
         } else if (vinfo->bits_per_pixel == 8) { /* 8bit Gray image */
             for (i = 0; i < height; i++) {
                 ptr = buf + raster_length * i;
                 for (j=0; j < vinfo->width; j++) {
-                    ptr[j] = min(255, frac2cv(gx_map_color_frac(pgs,
-                      cv2frac(ptr[j]), effective_transfer[3])));
+                    ptr[j] = frac2byte(gx_map_color_frac(pgs, byte2frac(ptr[j]), effective_transfer[3]));
                 }
             }
         }
@@ -4362,20 +4358,16 @@ opvp_image_plane_data(
             for (i = 0; i < height; i++) {
                 ptr = buf + raster_length * i;
                 for (j = 0; j < vinfo->width; j++) {
-                    ptr[j*3] = min(255, frac2cv(gx_map_color_frac(pgs,
-                      cv2frac(ptr[j*3]), effective_transfer.colored.red)));
-                    ptr[j*3+1] = min(255, frac2cv(gx_map_color_frac(pgs,
-                      cv2frac(ptr[j*3+1]), effective_transfer.colored.green)));
-                    ptr[j*3+2] = min(255, frac2cv(gx_map_color_frac(pgs,
-                      cv2frac(ptr[j*3+2]), effective_transfer.colored.blue)));
+                    ptr[j*3+0] = frac2byte(gx_map_color_frac(pgs, byte2frac(ptr[j*3+0]), effective_transfer.colored.red));
+                    ptr[j*3+1] = frac2byte(gx_map_color_frac(pgs, byte2frac(ptr[j*3+1]), effective_transfer.colored.green));
+                    ptr[j*3+2] = frac2byte(gx_map_color_frac(pgs, byte2frac(ptr[j*3+2]), effective_transfer.colored.blue));
                 }
             }
         } else if (vinfo->bits_per_pixel == 8) { /* 8bit Gray image */
             for (i = 0; i < height; i++) {
                 ptr = buf + raster_length * i;
                 for (j = 0; j < vinfo->width; j++) {
-                    ptr[j] = min(255, frac2cv(gx_map_color_frac(pgs,
-                      cv2frac(ptr[j]), effective_transfer.colored.gray)));
+                    ptr[j] = frac2byte(gx_map_color_frac(pgs, byte2frac(ptr[j]), effective_transfer.colored.gray));
                 }
             }
         }


Summary of changes:
 contrib/gdevgdi.c       |  6 ++++++
 contrib/gdevlx32.c      | 13 +++++++++---
 contrib/gdevmd2k.c      |  2 ++
 contrib/lips4/gdevl4r.c |  1 +
 contrib/lips4/gdevl4v.c | 13 +++++++++---
 contrib/opvp/gdevopvp.c | 55 +++++++++++++++++++++----------------------------
 6 files changed, 53 insertions(+), 37 deletions(-)