From 09b5b48560f3b934c2acc8c560576e8281a15b13 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Sun, 26 Mar 2000 23:42:57 -0800
Subject: [PATCH] fixed some undefined behaviour (ajabaja!)

Rev: src/modules/Image/encodings/_xpm.c:1.10
Rev: src/modules/Image/encodings/psd.c:1.15
Rev: src/modules/Image/encodings/tga.c:1.12
Rev: src/modules/Image/encodings/x.c:1.26
Rev: src/modules/_Image_TIFF/image_tiff.c:1.13
---
 src/modules/Image/encodings/_xpm.c   |  5 +++--
 src/modules/Image/encodings/psd.c    | 12 +++++++++---
 src/modules/Image/encodings/tga.c    | 21 ++++++++++++++-------
 src/modules/Image/encodings/x.c      | 10 +++++-----
 src/modules/_Image_TIFF/image_tiff.c | 12 +++++++++---
 5 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/src/modules/Image/encodings/_xpm.c b/src/modules/Image/encodings/_xpm.c
index e234b47696..822c53cc90 100644
--- a/src/modules/Image/encodings/_xpm.c
+++ b/src/modules/Image/encodings/_xpm.c
@@ -1,5 +1,5 @@
 #include "global.h"
-RCSID("$Id: _xpm.c,v 1.9 1999/10/26 22:54:03 marcus Exp $");
+RCSID("$Id: _xpm.c,v 1.10 2000/03/27 07:42:35 hubbe Exp $");
 
 #include "image_machine.h"
 
@@ -256,7 +256,8 @@ void f__xpm_write_rows( INT32 args )
           adst++;
         } else {
           dst++;
-          adst->r = adst->g = (adst++)->b = color.alpha;
+          adst->r = adst->g = adst->b = color.alpha;
+	  adst++;
         }
       }
     }
diff --git a/src/modules/Image/encodings/psd.c b/src/modules/Image/encodings/psd.c
index ca848d5fc4..be04eda463 100644
--- a/src/modules/Image/encodings/psd.c
+++ b/src/modules/Image/encodings/psd.c
@@ -1,5 +1,5 @@
 #include "global.h"
-RCSID("$Id: psd.c,v 1.14 2000/02/03 19:01:29 grubba Exp $");
+RCSID("$Id: psd.c,v 1.15 2000/03/27 07:42:35 hubbe Exp $");
 
 #include "image_machine.h"
 
@@ -386,7 +386,10 @@ static void f_decode_image_channel( INT32 args )
   io = clone_object( image_program, 2 );
   dst = ((struct image *)get_storage(io,image_program))->img;
   for(y=0; y<w*h; y++)
-    dst->r = dst->g = (dst++)->b = *(source++);
+  {
+    dst->r = dst->g = dst->b = *(source++);
+    dst++;
+  }
   pop_n_elems(args);
   push_object( io );
 }
@@ -458,7 +461,10 @@ static void f_decode_image_data( INT32 args )
          *dst++;
        }
        else
-         dst->r = dst->g = (dst++)->b = *(source++);
+       {
+         dst->r = dst->g = dst->b = *(source++);
+	 dst++;
+       }
        break;
     }
   }
diff --git a/src/modules/Image/encodings/tga.c b/src/modules/Image/encodings/tga.c
index 76aa1ee8ba..83e80aa1b7 100644
--- a/src/modules/Image/encodings/tga.c
+++ b/src/modules/Image/encodings/tga.c
@@ -1,6 +1,6 @@
 
 /*
- * $Id: tga.c,v 1.11 2000/03/10 04:53:16 per Exp $
+ * $Id: tga.c,v 1.12 2000/03/27 07:42:35 hubbe Exp $
  *
  *  Targa codec for pike. Based on the tga plugin for gimp.
  *
@@ -77,7 +77,7 @@
 #include "image.h"
 #include "colortable.h"
 
-RCSID("$Id: tga.c,v 1.11 2000/03/10 04:53:16 per Exp $");
+RCSID("$Id: tga.c,v 1.12 2000/03/27 07:42:35 hubbe Exp $");
 
 #ifndef MIN
 # define MIN(X,Y) ((X)<(Y)?(X):(Y))
@@ -664,7 +664,8 @@ static struct image_alpha ReadImage(struct buffer *fp, struct tga_header *hdr)
              (id++)->r = cmap[cmapind++];
              if(pelbytes>3)
              {
-               ad->r = ad->g = (ad++)->b = cmap[cmapind];
+               ad->r = ad->g = ad->b = cmap[cmapind];
+	       ad++;
              }
              sd++;
            }
@@ -673,10 +674,12 @@ static struct image_alpha ReadImage(struct buffer *fp, struct tga_header *hdr)
          for(y = 0; y<height; y++)
            for(x = 0; x<width; x++)
            {
-             id->r =  id->g = (id++)->b = *(sd++);
+             id->r =  id->g = id->b = *(sd++);
+	     id++;
              if(abpp)
              {
-               ad->r = ad->g = (ad++)->b = *(sd++);
+               ad->r = ad->g = ad->b = *(sd++);
+	       ad++;
              }
            }
          break;
@@ -690,7 +693,10 @@ static struct image_alpha ReadImage(struct buffer *fp, struct tga_header *hdr)
              if(abpp)
              {
                if( !really_no_alpha )
-                 ad->r = ad->g = (ad++)->b = *sd;
+	       {
+                 ad->r = ad->g = ad->b = *sd;
+		 add++;
+	       }
                sd++;
              }
            }
@@ -828,7 +834,8 @@ static struct buffer save_tga(struct image *img, struct image *alpha,
           *(p++) = is->b;
           *(p++) = is->g;
           *(p++) = (is++)->r;
-          *(p++) = ((int)as->r+(int)as->g*2+(as++)->b)/4;
+          *(p++) = ((int)as->r+(int)as->g*2+as->b)/4;
+	  as++;
         }
     } else {
       p = data = malloc( width*height*3 );
diff --git a/src/modules/Image/encodings/x.c b/src/modules/Image/encodings/x.c
index f476866acd..b8ef6e068d 100644
--- a/src/modules/Image/encodings/x.c
+++ b/src/modules/Image/encodings/x.c
@@ -1,9 +1,9 @@
-/* $Id: x.c,v 1.25 1999/10/19 16:07:34 marcus Exp $ */
+/* $Id: x.c,v 1.26 2000/03/27 07:42:35 hubbe Exp $ */
 
 /*
 **! module Image
 **! note
-**!	$Id: x.c,v 1.25 1999/10/19 16:07:34 marcus Exp $
+**!	$Id: x.c,v 1.26 2000/03/27 07:42:35 hubbe Exp $
 **! submodule X
 **!
 **!	This submodule handles encoding and decoding of
@@ -29,7 +29,7 @@
 #include <winsock.h>
 #endif
 
-RCSID("$Id: x.c,v 1.25 1999/10/19 16:07:34 marcus Exp $");
+RCSID("$Id: x.c,v 1.26 2000/03/27 07:42:35 hubbe Exp $");
 #include "pike_macros.h"
 #include "object.h"
 #include "constants.h"
@@ -349,8 +349,8 @@ static void image_x_encode_truecolor(INT32 args)
 	    }
 	    break;
          case 1:
-	    while (x--) *(d++)=swap_bits[*d];
-	    break;
+	   while (x--) { *d=swap_bits[*d]; d++; } /* Hope this is correct - Hubbe */
+	   break;
       }
    }
 
diff --git a/src/modules/_Image_TIFF/image_tiff.c b/src/modules/_Image_TIFF/image_tiff.c
index 521a23c4a0..64a6e38ed1 100644
--- a/src/modules/_Image_TIFF/image_tiff.c
+++ b/src/modules/_Image_TIFF/image_tiff.c
@@ -13,7 +13,7 @@
 
 
 #ifdef HAVE_LIBTIFF
-RCSID("$Id: image_tiff.c,v 1.12 2000/02/01 23:53:00 hubbe Exp $");
+RCSID("$Id: image_tiff.c,v 1.13 2000/03/27 07:42:57 hubbe Exp $");
 
 #include "global.h"
 #include "machine.h"
@@ -275,7 +275,10 @@ void low_image_tiff_encode( struct buffer *buf,
       *(b++)=is->g;
       *(b++)=(is++)->b;
       if(as)
-        *(b++)=(as->r + as->g*2 + (as++)->b)/4;
+      {
+        *(b++)=(as->r + as->g*2 + as->b)/4;
+	as++;
+      }
     }
     if(TIFFWriteScanline(tif, buffer, y, 0) < 0)
     {
@@ -348,7 +351,10 @@ void low_image_tiff_decode( struct buffer *buf,
     di->g = (p>>8) & 255;
     (di++)->b = (p>>16) & 255;
     if(!image_only) 
-      da->r = da->g = (da++)->b = (p>>24) & 255;
+    {
+      da->r = da->g = da->b = (p>>24) & 255;
+      da++;
+    }
     s++;
   }
   free(raster);
-- 
GitLab