diff --git a/.gitattributes b/.gitattributes
index 884509883fcbc1f5582e5bfa087cfbed75516ab6..1507662adbafb9b2a6fa98299309a18165b083a1 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -479,20 +479,16 @@ testfont binary
 /src/modules/Image/Makefile.in foreign_ident
 /src/modules/Image/acconfig.h foreign_ident
 /src/modules/Image/assembly.h foreign_ident
-/src/modules/Image/blit.c foreign_ident
 /src/modules/Image/blit_layer_include.h foreign_ident
 /src/modules/Image/colors.c foreign_ident
 /src/modules/Image/colors.h foreign_ident
-/src/modules/Image/colortable.c foreign_ident
 /src/modules/Image/colortable.h foreign_ident
 /src/modules/Image/colortable_lookup.h foreign_ident
 /src/modules/Image/configure.in foreign_ident
-/src/modules/Image/dct.c foreign_ident
 /src/modules/Image/default_font.c foreign_ident
 /src/modules/Image/encodings/Makefile.in foreign_ident
 /src/modules/Image/encodings/_xpm.c foreign_ident
 /src/modules/Image/encodings/any.c foreign_ident
-/src/modules/Image/encodings/atari.c foreign_ident
 /src/modules/Image/encodings/atari.h foreign_ident
 /src/modules/Image/encodings/avs.c foreign_ident
 /src/modules/Image/encodings/bmp.c foreign_ident
@@ -504,7 +500,6 @@ testfont binary
 /src/modules/Image/encodings/ilbm.c foreign_ident
 /src/modules/Image/encodings/neo.c foreign_ident
 /src/modules/Image/encodings/pcx.c foreign_ident
-/src/modules/Image/encodings/png.c foreign_ident
 /src/modules/Image/encodings/pnm.c foreign_ident
 /src/modules/Image/encodings/psd.c foreign_ident
 /src/modules/Image/encodings/psd_constant_strings.h foreign_ident
@@ -513,28 +508,19 @@ testfont binary
 /src/modules/Image/encodings/tga.c foreign_ident
 /src/modules/Image/encodings/tim.c foreign_ident
 /src/modules/Image/encodings/wbf.c foreign_ident
-/src/modules/Image/encodings/x.c foreign_ident
 /src/modules/Image/encodings/xbm.c foreign_ident
-/src/modules/Image/encodings/xcf.c foreign_ident
 /src/modules/Image/encodings/xcf_constant_strings.h foreign_ident
 /src/modules/Image/encodings/xwd.c foreign_ident
-/src/modules/Image/font.c foreign_ident
-/src/modules/Image/image.c foreign_ident
-/src/modules/Image/image.h foreign_ident
 /src/modules/Image/image_module.c foreign_ident
 /src/modules/Image/initstuff.h foreign_ident
 /src/modules/Image/layer_channel.h foreign_ident
 /src/modules/Image/layer_oper.h foreign_ident
-/src/modules/Image/layers.c foreign_ident
 /src/modules/Image/match.h foreign_ident
-/src/modules/Image/matrix.c foreign_ident
 /src/modules/Image/mkwmml.pike foreign_ident
 /src/modules/Image/operator.c foreign_ident
 /src/modules/Image/orient.c foreign_ident
-/src/modules/Image/pattern.c foreign_ident
 /src/modules/Image/phase.h foreign_ident
 /src/modules/Image/polyfill.c foreign_ident
-/src/modules/Image/search.c foreign_ident
 /src/modules/Image/testsuite.in foreign_ident
 /src/modules/JSON/JSON.pmod.in foreign_ident
 /src/modules/JSON/Makefile.in foreign_ident
diff --git a/src/modules/Image/blit.c b/src/modules/Image/blit.c
index 20a381d167f9d32a79b20416bed5df761e85378b..0bc19d44590776735e1399678ec68d4548a72a55 100644
--- a/src/modules/Image/blit.c
+++ b/src/modules/Image/blit.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: blit.c,v 1.60 2006/08/31 14:02:47 nilsson Exp $
+|| $Id$
 */
 
 #include "global.h"
@@ -216,7 +216,7 @@ void img_crop(struct image *dest,
    if (x1>x2) tmp=x1, x1=x2, x2=tmp;
    if (y1>y2) tmp=y1, y1=y2, y2=tmp;
 
-   new=xalloc( (x2-x1+1)*(y2-y1+1)*sizeof(rgb_group)+1 );
+   new=xalloc( (x2-x1+1)*(y2-y1+1)*sizeof(rgb_group)+RGB_VEC_PAD );
 
    if (x1==0 && y1==0 &&
        img->xsize-1==x2 && img->ysize-1==y2)
@@ -260,7 +260,7 @@ void img_crop(struct image *dest,
 void img_clone(struct image *newimg,struct image *img)
 {
    if (newimg->img) free(newimg->img);
-   newimg->img=xalloc(sizeof(rgb_group)*img->xsize*img->ysize+1);
+   newimg->img=xalloc(sizeof(rgb_group)*img->xsize*img->ysize+RGB_VEC_PAD);
    THREADS_ALLOW();
    MEMCPY(newimg->img,img->img,sizeof(rgb_group)*img->xsize*img->ysize);
    THREADS_DISALLOW();
diff --git a/src/modules/Image/colortable.c b/src/modules/Image/colortable.c
index 112ce338a54613d70c8b058f59591d8be96d4f7f..bbff030838e18c10a7f15bee545acb284035d357 100644
--- a/src/modules/Image/colortable.c
+++ b/src/modules/Image/colortable.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: colortable.c,v 1.133 2009/07/22 12:54:29 grubba Exp $
+|| $Id$
 */
 
 #include "global.h"
@@ -3715,7 +3715,7 @@ void image_colortable_map(INT32 args)
    dest=(struct image*)(o->storage);
    *dest=*src;
 
-   dest->img=malloc(sizeof(rgb_group)*src->xsize*src->ysize+1);
+   dest->img=malloc(sizeof(rgb_group)*src->xsize*src->ysize+RGB_VEC_PAD);
    if (!dest->img)
    {
       free_object(o);
diff --git a/src/modules/Image/dct.c b/src/modules/Image/dct.c
index 15482e00e5efb97d22d66ad4759734c3dc4f21dd..0979560fa6cee23bf9c3c2ba7c35d2ada2c021ba 100644
--- a/src/modules/Image/dct.c
+++ b/src/modules/Image/dct.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: dct.c,v 1.29 2005/08/15 17:00:39 grubba Exp $
+|| $Id$
 */
 
 /*
@@ -116,7 +116,7 @@ void image_dct(INT32 args)
    }
 
    if (!(img->img=(rgb_group*)malloc(sizeof(rgb_group)*
-				     img->xsize*img->ysize+1)))
+				     img->xsize*img->ysize+RGB_VEC_PAD)))
    {
       free(area);
       free(costbl);
diff --git a/src/modules/Image/encodings/atari.c b/src/modules/Image/encodings/atari.c
index a8e15bf92ab7278bd03ff11e1e87659175f90677..27255816a933b9f28d01b2f31e525d34a0d3ee2a 100644
--- a/src/modules/Image/encodings/atari.c
+++ b/src/modules/Image/encodings/atari.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: atari.c,v 1.4 2004/05/19 00:06:06 nilsson Exp $
+|| $Id$
 */
 
 #include "global.h"
@@ -49,7 +49,7 @@ struct atari_palette* decode_atari_palette(unsigned char *pal,
   struct atari_palette* ret_pal = xalloc(sizeof(struct atari_palette));
 
   ret_pal->size=size;
-  ret_pal->colors=xalloc(size*sizeof(rgb_group));
+  ret_pal->colors=xalloc(size*sizeof(rgb_group) + RGB_VEC_PAD);
 
   if(size==2)
   {
diff --git a/src/modules/Image/encodings/png.c b/src/modules/Image/encodings/png.c
index 9a1f5086d6e0d15619e66b26d99c13780b21327a..f3dd3b04d1a329832bb9cb7c881c4c17e5800207 100644
--- a/src/modules/Image/encodings/png.c
+++ b/src/modules/Image/encodings/png.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: png.c,v 1.101 2010/05/29 16:12:12 nilsson Exp $
+|| $Id$
 */
 
 #include "global.h"
@@ -992,9 +992,9 @@ static int _png_decode_idat(struct IHDR *ihdr, struct neo_colortable *ct,
   if( sp[-1].type!=T_STRING )
     Pike_error("Got illegal data from decompression.\n");
 
-  w1=xalloc(sizeof(rgb_group)*ihdr->width*ihdr->height);
+  w1=xalloc(sizeof(rgb_group)*ihdr->width*ihdr->height + RGB_VEC_PAD);
   SET_ONERROR(err, free_and_clear, &w1);
-  wa1=xalloc(sizeof(rgb_group)*ihdr->width*ihdr->height);
+  wa1=xalloc(sizeof(rgb_group)*ihdr->width*ihdr->height + RGB_VEC_PAD);
   SET_ONERROR(a_err, free_and_clear, &wa1);
 
   fs = sp[-1].u.string;
@@ -1029,9 +1029,9 @@ static int _png_decode_idat(struct IHDR *ihdr, struct neo_colortable *ct,
       int got_alpha = 0;
 
       /* need arena */
-      t1=xalloc(sizeof(rgb_group)*ihdr->width*ihdr->height);
+      t1=xalloc(sizeof(rgb_group)*ihdr->width*ihdr->height + RGB_VEC_PAD);
       SET_ONERROR(t_err, free_and_clear, &t1);
-      ta1=xalloc(sizeof(rgb_group)*ihdr->width*ihdr->height);
+      ta1=xalloc(sizeof(rgb_group)*ihdr->width*ihdr->height + RGB_VEC_PAD);
       SET_ONERROR(ta_err, free_and_clear, &ta1);
 
       /* loop over adam7 interlace's
@@ -1684,7 +1684,7 @@ static void image_png_encode(INT32 args)
 	 unsigned char *tmp, *ts;
 
          x = img->xsize;
-         tmp=xalloc(x*y);
+	 tmp=xalloc(x*y + RGB_VEC_PAD);
 
 	 image_colortable_index_8bit_image(ct,s,tmp,x*y,x);
          ps=begin_shared_string( y * ((x*bpp+7)/8+1) );
diff --git a/src/modules/Image/encodings/x.c b/src/modules/Image/encodings/x.c
index 2d1261d3c5e8c4f27c217f1a93107b48ef9ccd27..b66726b099ee053ecf7d37a73250f26fae8f2809 100644
--- a/src/modules/Image/encodings/x.c
+++ b/src/modules/Image/encodings/x.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: x.c,v 1.51 2008/06/16 21:56:24 mast Exp $
+|| $Id$
 */
 
 /*
@@ -203,7 +203,7 @@ static void image_x_encode_truecolor(INT32 args)
 
    if (nct) 
    {
-      tmp=(rgb_group*)xalloc(sizeof(rgb_group)*img->xsize*img->ysize +1);
+      tmp=(rgb_group*)xalloc(sizeof(rgb_group)*img->xsize*img->ysize +RGB_VEC_PAD);
       if (!image_colortable_map_image(nct,img->img,tmp,
 				      img->xsize*img->ysize,img->xsize))
       {
diff --git a/src/modules/Image/encodings/xcf.c b/src/modules/Image/encodings/xcf.c
index ff8efcc2c57c2fb65086ec04c5751775f089ca65..a2db46ddd0726084a7a370cf3915c40ea3e132ff 100644
--- a/src/modules/Image/encodings/xcf.c
+++ b/src/modules/Image/encodings/xcf.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: xcf.c,v 1.56 2008/01/22 21:23:51 grubba Exp $
+|| $Id$
 */
 
 #include "global.h"
@@ -1205,7 +1205,7 @@ void image_xcf_f__decode_tiles( INT32 args )
 
   if(cmap)
   {
-    colortable = xalloc(sizeof(rgb_group)*image_colortable_size( cmap ));
+    colortable = xalloc(sizeof(rgb_group)*image_colortable_size( cmap ) + RGB_VEC_PAD);
     SET_ONERROR(err, free, colortable);
     image_colortable_write_rgb( cmap, (unsigned char *)colortable );
   }
diff --git a/src/modules/Image/font.c b/src/modules/Image/font.c
index 7f2475ed943b3138d7f54cfe8c7bc0f566114f47..f903d28914a7d581477b74f14fd3e216119b5bfa 100644
--- a/src/modules/Image/font.c
+++ b/src/modules/Image/font.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: font.c,v 1.92 2010/07/27 16:46:05 mast Exp $
+|| $Id$
 */
 
 #include "global.h"
@@ -605,7 +605,7 @@ void font_write(INT32 args)
    else
      img->ysize = this->height;
    img->rgb.r=img->rgb.g=img->rgb.b=255;
-   img->img=malloc(img->xsize*img->ysize*sizeof(rgb_group)+1);
+   img->img=malloc(img->xsize*img->ysize*sizeof(rgb_group)+RGB_VEC_PAD);
 
    if (!img->img) {
      free_object(o);
diff --git a/src/modules/Image/image.c b/src/modules/Image/image.c
index 811f5211c0f02143f9c5c980c9fcb3b6ab6bb843..317eb95a249a98b56e1cc84b9ca8a5ef105fa437 100644
--- a/src/modules/Image/image.c
+++ b/src/modules/Image/image.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: image.c,v 1.236 2009/07/21 14:25:52 grubba Exp $
+|| $Id$
 */
 
 /*
@@ -409,7 +409,7 @@ THREADS_ALLOW();
    
 THREADS_DISALLOW();
 
-   d=xalloc(sizeof(rgb_group)*img->xsize*img->ysize + 1);
+   d=xalloc(sizeof(rgb_group)*img->xsize*img->ysize + RGB_VEC_PAD);
 
 THREADS_ALLOW();
 CHRONO("apply_matrix, one");
@@ -631,7 +631,7 @@ void img_read_grey(INT32 args)
    int n=THIS->xsize*THIS->ysize;
    rgb_group *d;
    img_read_get_channel(1,"grey",args,&m1,&s1,&c1);
-   d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+1);
+   d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD);
    switch (m1)
    {
       case 0: MEMSET(d,c1,n*sizeof(rgb_group)); break;
@@ -649,7 +649,7 @@ void img_read_rgb(INT32 args)
    img_read_get_channel(1,"red",args,&m1,&s1,&(rgb.r));
    img_read_get_channel(2,"green",args,&m2,&s2,&(rgb.g));
    img_read_get_channel(3,"blue",args,&m3,&s3,&(rgb.b));
-   d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+1);
+   d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD);
 
    switch (m1|(m2<<4)|(m3<<4))
    {
@@ -703,7 +703,7 @@ void img_read_cmyk(INT32 args)
    img_read_get_channel(2,"magenta",args,&m2,&s2,&(rgb.g));
    img_read_get_channel(3,"yellow",args,&m3,&s3,&(rgb.b));
    img_read_get_channel(4,"black",args,&m4,&s4,&k);
-   d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+1);
+   d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD);
 
    while (n--)
    {
@@ -742,7 +742,7 @@ void img_read_adjusted_cmyk(INT32 args)
    img_read_get_channel(2,"magenta",args,&m2,&s2,&(rgb.g));
    img_read_get_channel(3,"yellow",args,&m3,&s3,&(rgb.b));
    img_read_get_channel(4,"black",args,&m4,&s4,&k);
-   d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+1);
+   d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD);
 
    while (n--)
    {
@@ -799,7 +799,7 @@ void img_read_cmy(INT32 args)
    img_read_get_channel(1,"cyan",args,&m1,&s1,&(rgb.r));
    img_read_get_channel(2,"magenta",args,&m2,&s2,&(rgb.g));
    img_read_get_channel(3,"yellow",args,&m3,&s3,&(rgb.b));
-   d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+1);
+   d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD);
 
    while (n--)
    {
@@ -912,7 +912,7 @@ void image_create_method(INT32 args)
       if (args<2) push_int(0);
 
       THIS->img=(rgb_group*)
-	 xalloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+	 xalloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
 
       if (args>2) pop_n_elems(args-2);
       push_int(0); stack_swap();
@@ -964,7 +964,7 @@ void image_create(INT32 args)
    else
       getrgb(THIS,2,args,args,"Image.Image->create()"); 
 
-   THIS->img=xalloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+   THIS->img=xalloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
 
    img_clear(THIS->img,THIS->rgb,THIS->xsize*THIS->ysize);
    pop_n_elems(args);
@@ -1041,7 +1041,7 @@ void image_clone(INT32 args)
    if (img->xsize<0) img->xsize=1;
    if (img->ysize<0) img->ysize=1;
 
-   img->img=xalloc(sizeof(rgb_group)*img->xsize*img->ysize+1);
+   img->img=xalloc(sizeof(rgb_group)*img->xsize*img->ysize+RGB_VEC_PAD);
    if (THIS->img)
    {
       if (img->xsize==THIS->xsize
@@ -1095,12 +1095,12 @@ void image_clear(INT32 args)
 
    getrgb(img,0,args,args,"Image.Image->clear()"); 
 
-   img->img=malloc(sizeof(rgb_group)*img->xsize*img->ysize+1);
+   img->img=malloc(sizeof(rgb_group)*img->xsize*img->ysize+RGB_VEC_PAD);
    if (!img->img)
    {
      free_object(o);
      SIMPLE_OUT_OF_MEMORY_ERROR("clear",
-				sizeof(rgb_group)*img->xsize*img->ysize+1);
+				sizeof(rgb_group)*img->xsize*img->ysize+RGB_VEC_PAD);
    }
 
    img_clear(img->img,img->rgb,img->xsize*img->ysize);
@@ -1225,11 +1225,11 @@ static void image_change_color(INT32 args)
    img=(struct image*)(o->storage);
    *img=*THIS;
 
-   if (!(img->img=malloc(sizeof(rgb_group)*img->xsize*img->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*img->xsize*img->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("change_color",
-				 sizeof(rgb_group)*img->xsize*img->ysize+1);
+				 sizeof(rgb_group)*img->xsize*img->ysize+RGB_VEC_PAD);
    }
 
    left=THIS->xsize*THIS->ysize;
@@ -2285,11 +2285,11 @@ void image_grey(INT32 args)
    o=clone_object(image_program,0);
    img=(struct image*)o->storage;
    *img=*THIS;
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("grey",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
 
    d=img->img;
@@ -2377,11 +2377,11 @@ void image_color(INT32 args)
    o=clone_object(image_program,0);
    img=(struct image*)o->storage;
    *img=*THIS;
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("color",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
 
    d=img->img;
@@ -2445,10 +2445,10 @@ void image_invert(INT32 args)
    img=(struct image*)o->storage;
    *img=*THIS;
    sz = sizeof(rgb_group)*THIS->xsize * THIS->ysize;
-   if (!(img->img=malloc(sz + 1)))
+   if (!(img->img=malloc(sz + RGB_VEC_PAD)))
    {
       free_object(o);
-      SIMPLE_OUT_OF_MEMORY_ERROR("invert", sz + 1);
+      SIMPLE_OUT_OF_MEMORY_ERROR("invert", sz + RGB_VEC_PAD);
    }
 
    d = (char *)img->img;
@@ -2538,11 +2538,11 @@ void image_threshold(INT32 args)
    o=clone_object(image_program,0);
    img=(struct image*)o->storage;
    *img=*THIS;
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("threshold",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
 
    d=img->img;
@@ -2662,11 +2662,11 @@ void image_hsv_to_rgb(INT32 args)
    img=(struct image*)o->storage;
    *img=*THIS;
 
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("hsv_to_rgb",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
 
    d=img->img;
@@ -2749,11 +2749,11 @@ void image_rgb_to_hsv(INT32 args)
    img=(struct image*)o->storage;
    *img=*THIS;
 
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("rgb_to_hsv",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
 
    d=img->img;
@@ -2877,11 +2877,11 @@ void image_yuv_to_rgb(INT32 args)
    img=(struct image*)o->storage;
    *img=*THIS;
 
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("yuv_to_rgb",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
 
    d=img->img;
@@ -2932,11 +2932,11 @@ void image_rgb_to_yuv(INT32 args)
    img=(struct image*)o->storage;
    *img=*THIS;
 
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("rgb_to_yuv",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
 
    d=img->img;
@@ -3026,11 +3026,11 @@ void image_distancesq(INT32 args)
    o=clone_object(image_program,0);
    img=(struct image*)o->storage;
    *img=*THIS;
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("distancesq",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
 
    d=img->img;
@@ -3239,11 +3239,11 @@ void image_select_from(INT32 args)
    o=clone_object(image_program,0);
    img=(struct image*)o->storage;
    *img=*THIS;
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("select_from",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
    MEMSET(img->img,0,sizeof(rgb_group)*img->xsize*img->ysize);
 
@@ -3900,7 +3900,7 @@ void image_modify_by_intensity(INT32 args)
    div=rgb.r+rgb.g+rgb.b;
    if (!div) div=1;
 
-   s=xalloc(sizeof(rgb_group)*(args-3)+1);
+   s=xalloc(sizeof(rgb_group)*(args-3)+RGB_VEC_PAD);
 
    for (x=0; x<args-3; x++)
    {
@@ -3924,12 +3924,12 @@ void image_modify_by_intensity(INT32 args)
       else s[x].r=s[x].g=s[x].b=0;
    }
 
-   list=malloc(sizeof(rgb_group)*256+1);
+   list=malloc(sizeof(rgb_group)*256+RGB_VEC_PAD);
    if (!list) 
    {
       free(s);
       SIMPLE_OUT_OF_MEMORY_ERROR("modify_by_intensity",
-				 sizeof(rgb_group)*256+1);
+				 sizeof(rgb_group)*256+RGB_VEC_PAD);
    }
    for (x=0; x<args-4; x++)
    {
@@ -3950,12 +3950,12 @@ void image_modify_by_intensity(INT32 args)
    o=clone_object(image_program,0);
    img=(struct image*)o->storage;
    *img=*THIS;
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       free(list);
       SIMPLE_OUT_OF_MEMORY_ERROR("modify_by_intensity",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
 
    d=img->img;
@@ -4303,11 +4303,11 @@ void image_gamma(INT32 args)
    o=clone_object(image_program,0);
    img=(struct image*)o->storage;
    *img=*THIS;
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("gamma",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
 
    d=img->img;
@@ -4850,7 +4850,7 @@ void image__decode( INT32 args )
 
     THIS->xsize = w;
     THIS->ysize = h;
-    THIS->img = xalloc( sizeof(rgb_group)*w*h+1 );
+    THIS->img = xalloc( sizeof(rgb_group)*w*h+RGB_VEC_PAD );
 
     memcpy( THIS->img, a->item[2].u.string->str, a->item[2].u.string->len );
     pop_stack();
diff --git a/src/modules/Image/image.h b/src/modules/Image/image.h
index 09b09f81a0ef11280c9a54c50fb86b4bfca7df19..e4df92c88465d862c339683f98b1e90ee0c7520a 100644
--- a/src/modules/Image/image.h
+++ b/src/modules/Image/image.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: image.h,v 1.51 2003/01/27 11:59:14 mirar Exp $
+|| $Id$
 */
 
 #ifdef PIKE_IMAGE_IMAGE_H
@@ -71,6 +71,15 @@ static inline INT32 FLOAT_TO_COLORL(double X)
 	(((INT32)((X)*((float)(COLORLMAX/256))))*256+((INT32)((X)*255)))
 #endif /* __ECL */
 
+#ifdef USE_VALGRIND
+/* Workaround for valgrind false alarms: gcc (4.2.3) can generate code
+ * that reads a full native integer from memory when we retrieve an
+ * rgb_group. This makes valgrind complain if it's done past the end
+ * of an alloc'ed block, so pad some extra. */
+#define RGB_VEC_PAD (SIZEOF_CHAR_P - sizeof (rgb_group))
+#else
+#define RGB_VEC_PAD 1
+#endif
 
 #define FS_SCALE 1024
 
diff --git a/src/modules/Image/layers.c b/src/modules/Image/layers.c
index 87c1d5294e96cc51f4de959a9282cffe70a7e8af..324c35105f926c87cf82c5deff571540e0d46364 100644
--- a/src/modules/Image/layers.c
+++ b/src/modules/Image/layers.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: layers.c,v 1.100 2008/01/16 19:42:57 grubba Exp $
+|| $Id$
 */
 
 /*
@@ -2774,10 +2774,10 @@ void img_lay(struct layer **layer,
    int xoffs=dest->xoffs,xsize=dest->xsize;
 
 #ifdef LAYERS_DUAL
-   line1=malloc(sizeof(rgb_group)*width);
-   aline1=malloc(sizeof(rgb_group)*width);
-   line2=malloc(sizeof(rgb_group)*width);
-   aline2=malloc(sizeof(rgb_group)*width);
+   line1=malloc(sizeof(rgb_group)*width + RGB_VEC_PAD);
+   aline1=malloc(sizeof(rgb_group)*width + RGB_VEC_PAD);
+   line2=malloc(sizeof(rgb_group)*width + RGB_VEC_PAD);
+   aline2=malloc(sizeof(rgb_group)*width + RGB_VEC_PAD);
    if (!line1 || !aline1
        !line2 || !aline2)
    {
@@ -2785,7 +2785,7 @@ void img_lay(struct layer **layer,
       if (aline1) free(aline1);
       if (line2) free(line2);
       if (aline2) free(aline2);
-      resource_error(NULL,0,0,"memory",sizeof(rgb_group)*4*width,
+      resource_error(NULL,0,0,"memory",4*(sizeof(rgb_group)*width + RGB_VEC_PAD),
 		     "Out of memory.\n");
    }
 #endif
diff --git a/src/modules/Image/matrix.c b/src/modules/Image/matrix.c
index 8d8a21a3348fe905a868b3c1e03b228c6d76e8a5..8ade9c72f03c854a7c55fe26095c9cd0a9c3db8d 100644
--- a/src/modules/Image/matrix.c
+++ b/src/modules/Image/matrix.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: matrix.c,v 1.52 2010/08/14 16:07:30 jonasw Exp $
+|| $Id$
 */
 
 /*
@@ -216,7 +216,7 @@ CHRONO("scale begin");
 			source->img, y, source->xsize);
    }
 
-   dest->img=d=malloc(newx*newy*sizeof(rgb_group)+1);
+   dest->img=d=malloc(newx*newy*sizeof(rgb_group)+RGB_VEC_PAD);
    if (d) 
    {
 
@@ -258,7 +258,7 @@ void img_scale2(struct image *dest, struct image *source)
    if (!newx) newx = 1;
    if (!newy) newy = 1;
 
-   new=xalloc(newx*newy*sizeof(rgb_group)+1);
+   new=xalloc(newx*newy*sizeof(rgb_group)+RGB_VEC_PAD);
 
    THREADS_ALLOW();
    MEMSET(new,0,newx*newy*sizeof(rgb_group));
@@ -460,11 +460,11 @@ void image_ccw(INT32 args)
    o=clone_object(image_program,0);
    img=(struct image*)o->storage;
    *img=*THIS;
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("ccw",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
    img->xsize=THIS->ysize;
    img->ysize=THIS->xsize;
@@ -493,7 +493,7 @@ static void img_cw(struct image *is,struct image *id)
 
    if (id->img) free(id->img);
    *id=*is;
-   if (!(id->img=malloc(sizeof(rgb_group)*is->xsize*is->ysize+1)))
+   if (!(id->img=malloc(sizeof(rgb_group)*is->xsize*is->ysize+RGB_VEC_PAD)))
       resource_error(NULL,0,0,"memory",0,"Out of memory.\n");
 
    id->xsize=is->ysize;
@@ -519,7 +519,7 @@ void img_ccw(struct image *is,struct image *id)
 
    if (id->img) free(id->img);
    *id=*is;
-   if (!(id->img=malloc(sizeof(rgb_group)*is->xsize*is->ysize+1)))
+   if (!(id->img=malloc(sizeof(rgb_group)*is->xsize*is->ysize+RGB_VEC_PAD)))
       resource_error(NULL,0,0,"memory",0,"Out of memory.\n");
 
    id->xsize=is->ysize;
@@ -569,11 +569,11 @@ void image_cw(INT32 args)
    o=clone_object(image_program,0);
    img=(struct image*)o->storage;
    *img=*THIS;
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("cw",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
    ys=img->xsize=THIS->ysize;
    i=xs=img->ysize=THIS->xsize;
@@ -623,11 +623,11 @@ void image_mirrorx(INT32 args)
    o=clone_object(image_program,0);
    img=(struct image*)o->storage;
    *img=*THIS;
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("mirrorx",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
 
    i=THIS->ysize;
@@ -674,11 +674,11 @@ void image_mirrory(INT32 args)
    o=clone_object(image_program,0);
    img=(struct image*)o->storage;
    *img=*THIS;
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("mirrory",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
 
    i=THIS->ysize;
@@ -720,7 +720,7 @@ static void img_skewx(struct image *src,
    len=src->xsize;
 
    if (!src->xsize) dest->xsize=0;
-   d=dest->img=malloc(sizeof(rgb_group)*dest->xsize*dest->ysize+1);
+   d=dest->img=malloc(sizeof(rgb_group)*dest->xsize*dest->ysize+RGB_VEC_PAD);
    if (!d) return;
    s=src->img;
 
@@ -808,7 +808,7 @@ static void img_skewy(struct image *src,
    len=src->ysize;
 
    if (!src->ysize) dest->ysize=0;
-   d=dest->img=malloc(sizeof(rgb_group)*dest->ysize*dest->xsize+1);
+   d=dest->img=malloc(sizeof(rgb_group)*dest->ysize*dest->xsize+RGB_VEC_PAD);
    if (!d) return;
    s=src->img;
 
@@ -1198,11 +1198,11 @@ void img_translate(INT32 args,int expand)
    img->xsize=THIS->xsize+(xt!=0);
    img->ysize=THIS->ysize+(xt!=0);
 
-   if (!(img->img=malloc(sizeof(rgb_group)*img->xsize*img->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*img->xsize*img->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("translate",
-				 sizeof(rgb_group)*img->xsize*img->ysize+1);
+				 sizeof(rgb_group)*img->xsize*img->ysize+RGB_VEC_PAD);
    }
 
    if (!xt)
diff --git a/src/modules/Image/pattern.c b/src/modules/Image/pattern.c
index 41d0e375cc942e790ff7884202d9601a0b01e9b0..4f4ffefa179f4c28b236f4e809c05fa86d874008 100644
--- a/src/modules/Image/pattern.c
+++ b/src/modules/Image/pattern.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: pattern.c,v 1.33 2005/08/15 17:00:39 grubba Exp $
+|| $Id$
 */
 
 /*
@@ -379,11 +379,11 @@ void image_noise(INT32 args)
    o=clone_object(image_program,0);
    img=(struct image*)o->storage;
    *img=*THIS;
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("noise",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
 
    cscale*=COLORRANGE_LEVELS;
@@ -460,11 +460,11 @@ void image_turbulence(INT32 args)
    o=clone_object(image_program,0);
    img=(struct image*)o->storage;
    *img=*THIS;
-   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)))
+   if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))
    {
       free_object(o);
       SIMPLE_OUT_OF_MEMORY_ERROR("noise",
-				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+1);
+				 sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
    }
 
    cscale*=COLORRANGE_LEVELS;
diff --git a/src/modules/Image/search.c b/src/modules/Image/search.c
index 489437212c9bb7f74f23a3bd8ad01d4413e68455..63dfeeaa10ab766db586603a5c586538da007683 100644
--- a/src/modules/Image/search.c
+++ b/src/modules/Image/search.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: search.c,v 1.33 2005/08/15 17:00:39 grubba Exp $
+|| $Id$
 */
 
 /*
@@ -509,7 +509,7 @@ void img_apply_max(struct image *dest,
    double qr,qg,qb;
    register double r=0,g=0,b=0;
 
-   d=xalloc(sizeof(rgb_group)*img->xsize*img->ysize+1);
+   d=xalloc(sizeof(rgb_group)*img->xsize*img->ysize+RGB_VEC_PAD);
 
 THREADS_ALLOW();