On 17/06/11 16:52, Stephanie Stroka wrote: > Am 17.06.2011 17:49, schrieb Tom Hughes: >> On 17/06/11 16:45, Stephanie Stroka wrote: >> >>> My code at that position looks like this: >>> >>> 284 static uint* sort(uint** matrix, uint width, uint height) { >>> 285 uint* data = (uint*) malloc(width * height * sizeof(uint)); >>> 286 uint i,j=0; >>> 287 for(i=0; i<height; i++) { >>> 288 for(j=0; j<width; j++) { >>> 289 data[j + i*height] = matrix[i][j]; >>> 290 } >>> 291 } >>> ... >>> >>> I don't see why I'm using an invalid write of size 4. I'm retrieving an >>> uint and I'm writing an uint. >> >> The write it is complaining about is at line 293 and you haven't shown >> us that line ;-) >> >> What it is saying is that you are writing beyond the end of the array. > > Ups, sorry... I refactored the code and ran it again, but I didn't post > the correct log msg.
Ah... Your index calculation is the wrong way round. You should be doing "i + j * height" as j is counting the columns and the index needs to advance by the height of the matrix as the column number increases. Tom -- Tom Hughes (t...@compton.nu) http://compton.nu/ ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users