Am facing a strange problem. On debugging the code it is seen that a local double array in a function overlaps the memory address of a passed integer array.
How is such an issue taken care of in a foolproof manner?
Thanks,
Am facing a strange problem. On debugging the code it is seen that a local double array in a function overlaps the memory address of a passed integer array.
How is such an issue taken care of in a foolproof manner?
Thanks,
Last edited by wots_guge; 06-05-2006 at 09:47 PM.
Can you show us the code which resulted in this, and the resulting disassembly if possible?
The entire code runs into a few thousand lines and am not sure if snippet would help.Originally Posted by Tonto
This problem occurs on increasing the dimensions of memory required, the addresses looks like this:
&S[1] (int array passed to function): 0x00433a24
&wts[i] (double array - local to function): 0x004339a8
as index i increases it forces contents of S to change and leads in crash (as per this progm logic).
Does this info help? Has anyone come across something similar, why does stack memory creep into heap?
> Does this info help? Has anyone come across something similar, why does stack memory creep into heap?
A question like this came up in a thread about exceeding the memory with an STL container on comp.lang.c++.moderated, and I feel that you may find the answer to this question there when you start reading. I know that you aren't using STL containers, but this is very closely related.
copy pasta: http://groups.google.com/group/comp....806e916abf26d3
Post the current function, and the function which calls it.
Plus any declarations for sizes of objects or types.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
The link by citizen is a red herring in this. If adding to an STL container failed, an exception will have been thrown, so you could not pass a pointer to data it contains. The only way you could trigger this problem in that circumstance would be to catch the exception and act as if no error had occurred (and then yield undefined behaviour by assuming the container contains more than it does).
At a guess (without seeing code), the problem is that the your function is falling off the end of the double array. The difference (in bytes, I assume) between the addresses you've quoted is 7C (124), which means that (effectively) writing to wts[i] with i 15 or more will overwrite your passed integer array.
Another possible cause of the effect you're seeing is that you're passing an uninitialised pointer as an argument to the function (and the value passed happens to correspond to your double array + 124 bytes offset).
Either way, you're getting undefined behaviour.