Re: Integer changes mid-execution

View: New views
3 Messages — Rating Filter:   Alert me  

Re: Integer changes mid-execution

by nmm1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Nov 3 2009, Nishita Desai wrote:
>
>What happens is that suddenly at the end of the third iteration,
>NPART changes value. Here is a gdb transcript:
>
>Can anyone tell me what is going wrong?  I appreciate any help!

Somewhere in the code you are executing, you are overwriting NPART.

That is usually due to a subscript being larger than the size of an
array, but there are many other possible causes.  Start by checking
the size of the array P, and then check that you haven't aliased NPART
to part of P (e.g. by passing P(3,1020) as an argument called NPART).
If neither is the case, the bug is a bit nasty, and is located in
some code executed previously.

But, sure as eggs is little chickens, that will be the cause.

Regards,
Nick Maclaren.


Re: Integer changes mid-execution

by Nishita Desai-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Nov 3, 2009 at 17:19, N.M. Maclaren <nmm1@...> wrote:
> On Nov 3 2009, Nishita Desai wrote:
>>
>> What happens is that suddenly at the end of the third iteration,
>> NPART changes value. Here is a gdb transcript:
>>
> Somewhere in the code you are executing, you are overwriting NPART.
> That is usually due to a subscript being larger than the size of an
> array, but there are many other possible causes.

Thanks for your reply Nick.  You were right, that was the case.
However, I don't understand why this should happen.  I can understand
if P(I,NPART) points to some garbage value, or that I shall get a
segmentation fault.  But why is the array index variable overwritten?

Thanks again,
Nishita

Re: Integer changes mid-execution

by Jerry DeLisle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 11/03/2009 05:21 AM, Nishita Desai wrote:

> On Tue, Nov 3, 2009 at 17:19, N.M. Maclaren<nmm1@...>  wrote:
>> On Nov 3 2009, Nishita Desai wrote:
>>>
>>> What happens is that suddenly at the end of the third iteration,
>>> NPART changes value. Here is a gdb transcript:
>>>
>> Somewhere in the code you are executing, you are overwriting NPART.
>> That is usually due to a subscript being larger than the size of an
>> array, but there are many other possible causes.
>
> Thanks for your reply Nick.  You were right, that was the case.
> However, I don't understand why this should happen.  I can understand
> if P(I,NPART) points to some garbage value, or that I shall get a
> segmentation fault.  But why is the array index variable overwritten?

If memory is being overwritten beyond the extent of an array you likely will hit
other variables that are stored in adjacent locations.

Try -fbounds-check when you compile.  It may give you some interesting results.

Jerry