summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Deutschmann <whissi@gentoo.org>2020-03-19 13:53:45 +0100
committerThomas Deutschmann <whissi@gentoo.org>2020-08-13 11:28:25 +0200
commitdc2ba49207af71193f1390d84bba4e15aeea0ce0 (patch)
tree79c2a51cb5fa2b87800b1113e0015a7108cd2eb3 /base/gsbitcom.c
parentImport Ghostscript 9.50 (diff)
downloadghostscript-gpl-patches-ghostscript-9.52.tar.gz
ghostscript-gpl-patches-ghostscript-9.52.tar.bz2
ghostscript-gpl-patches-ghostscript-9.52.zip
Import Ghostscript 9.52ghostscript-9.52
Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>
Diffstat (limited to 'base/gsbitcom.c')
-rw-r--r--base/gsbitcom.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/base/gsbitcom.c b/base/gsbitcom.c
index 5af03642..6c8c78fe 100644
--- a/base/gsbitcom.c
+++ b/base/gsbitcom.c
@@ -13,6 +13,7 @@
CA 94945, U.S.A., +1(415)492-9861, for further information.
*/
+#include <assert.h>
/* Oversampled bitmap compression */
#include "std.h"
@@ -128,6 +129,34 @@ bits_compress_scaled(const byte * src, int srcx, uint width, uint height,
byte *d = dest;
uint h;
+ /* Assert some preconditions are satisfied: */
+
+ /* log2_x and log2_y must each be 0, 1 or 2. */
+ assert(log2_x >= 0 && log2_x < 3);
+ assert(log2_y >= 0 && log2_y < 3);
+
+ /* srcx and width must be multiple of xscale. */
+ assert(srcx % xscale == 0);
+ assert(width % xscale == 0);
+
+ /* height must be multiple of yscale. */
+ assert(height % yscale == 0);
+
+ /* because xscale is 1, 2 or 4 and srcx is a multiple of xscale,
+ in_shift_initial ends up being constrained as follows: */
+ if (log2_x == 0) {
+ /* in_shift_initial is {0,1,2,3,4,5,6,7]} */
+ assert(in_shift_initial >= 0 && in_shift_initial < 8);
+ }
+ if (log2_x == 1) {
+ /* in_shift_initial is {0,2,4,6}. */
+ assert(in_shift_initial >= 0 && in_shift_initial < 7 && in_shift_initial % 2 == 0);
+ }
+ if (log2_x == 2) {
+ /* in_shift_initial is {0,4} */
+ assert(in_shift_initial == 0 || in_shift_initial == 4);
+ }
+
for (h = height; h; srow += sskip, h -= yscale) {
const byte *s = srow;
@@ -196,8 +225,11 @@ bits_compress_scaled(const byte * src, int srcx, uint width, uint height,
for (index = 0, count = 0; index != sskip;
index += sraster
- )
+ ) {
+ /* Coverity 94484 incorrectly thinks in_shift can be negative. */
+ /* coverity[negative_shift] */
count += half_byte_1s[(s[index] >> in_shift) & mask];
+ }
if (count != 0 && table[count] == 0) { /* Look at adjacent cells to help prevent */
/* dropouts. */
uint orig_count = count;