|
From: Tom H. <to...@co...> - 2011-06-17 16:02:53
|
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 (to...@co...)
http://compton.nu/
|