fix for invalid use of memset when loading tiff images
authorCampbell Barton <ideasman42@gmail.com>
Mon, 23 Apr 2012 23:57:17 +0000 (23:57 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 23 Apr 2012 23:57:17 +0000 (23:57 +0000)
- memset(..., 1.0); // isnt valid
- memset(pointer, sizeof(pointer)) // was using the sizeof the pointer, not the size of the array, since this was to fill in alpha values it was obviously wrong.

source/blender/blenlib/BLI_math_vector.h
source/blender/blenlib/intern/math_vector.c
source/blender/imbuf/intern/tiff.c

index 54c066161101dcb3944b2c3e3f83ef712a232bd2..af3df9c9ed29726504c75e36cabfdc96added31c 100644 (file)
@@ -228,6 +228,7 @@ void add_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_
 void sub_vn_vn(float *array_tar, const float *array_src, const int size);
 void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size);
 void fill_vn_i(int *array_tar, const int size, const int val);
+void fill_vn_ushort(unsigned short *array_tar, const int size, const unsigned short val);
 void fill_vn_fl(float *array_tar, const int size, const float val);
 
 #ifdef __cplusplus
index 4b3ba7244d473867ed1ba6e1f7efe00826a196e6..f734e01943f740605b02cf9a673f32671ffddfa2 100644 (file)
@@ -561,6 +561,15 @@ void fill_vn_i(int *array_tar, const int size, const int val)
        }
 }
 
+void fill_vn_ushort(unsigned short *array_tar, const int size, const unsigned short val)
+{
+       unsigned short *tar = array_tar + (size - 1);
+       int i = size;
+       while (i--) {
+               *(tar--) = val;
+       }
+}
+
 void fill_vn_fl(float *array_tar, const int size, const float val)
 {
        float *tar = array_tar + (size - 1);
index f81fb740ff09da782f2547b262d330fd2df353f1..08b2e608c8e019fd7e9885fd90b97bafe1c5020d 100644 (file)
@@ -439,7 +439,7 @@ static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image, int premul)
                                
                                if (bitspersample == 32) {
                                        if (chan == 3 && spp == 3) /* fill alpha if only RGB TIFF */
-                                               memset(fbuf, 1.0, sizeof(fbuf));
+                                               fill_vn_fl(fbuf, ibuf->x, 1.0f);
                                        else
                                                success |= TIFFReadScanline(image, fbuf, row, chan);
                                        scanline_separate_32bit(tmpibuf->rect_float+ib_offset, fbuf, ibuf->x, chan);
@@ -447,7 +447,7 @@ static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image, int premul)
                                }
                                else if (bitspersample == 16) {
                                        if (chan == 3 && spp == 3) /* fill alpha if only RGB TIFF */
-                                               memset(sbuf, 65535, sizeof(sbuf));
+                                               fill_vn_ushort(sbuf, ibuf->x, 65535);
                                        else
                                                success |= TIFFReadScanline(image, sbuf, row, chan);
                                        scanline_separate_16bit(tmpibuf->rect_float+ib_offset, sbuf, ibuf->x, chan);