0

So I declared an array of type rgbtriple as in

RGBTRIPLE* buffer = malloc(sizeof(bi.biWidth));

and now i want to read in each pixel n times, so using a for loop like

for(int m = 0; m < n ; n++)

{

(buffer + x)->rgbtBlue = triple.rgbtBlue;

(buffer + x)->rgbtGreen = triple.rgbtGreen;

(buffer + x)->rgbtRed = triple.rgbtRed;

x++;

}

also tried directly as

for(int m = 0; m < n ; n++)

{

buffer[x] = triple;

x++;

}

running valgrind it says

Invalid write of size 1
==2627== at 0x42ED25: main (resize.c:119)
==2627== Address 0x617e544 is 0 bytes after a block of size 4 alloc'd
==2627== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2627== by 0x42E7C1: main (resize.c:90)

for line buffer[x] = triple;

any ideas....

I think it has to do with the size of the structure but rgbtriple should be of 3 bytes. Can't think where I got wrong.

0

sry for bad question RGBTRIPLE* buffer = malloc(sizeof(RGBTRIPLE)*bi.biWidth);

1
  • Good catch! Be sure to accept your answer when the system allows it (2 days from now usually). Feb 12 '17 at 19:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .