WTF is going on! Corrupt value that is never assigned

Moritz Maxeiner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 13 13:35:19 PDT 2017


On Thursday, 13 July 2017 at 18:22:34 UTC, FoxyBrown wrote:
> The following code is pretty screwed up, even though it doesn't 
> look like it. I have a buf, a simple malloc which hold the 
> results of a win32 call. I am then trying to copy over the data 
> in buf to a D struct.
>
> But when copying the strings, the buf location changes, 
> screwing up the copying process. It shouldn't happen, buf never 
> changes value anywhere except the first malloc(which is once). 
> Somehow it is getting changed, but where?
>
> [...]
>
> The buf value changes when calling cstr2dstr but I've had it 
> with other values to(any function call such as to!string, etc 
> seems to trigger it).
>
> [...]

- Does this happen every time, or only sometimes?
- At which loop iteration does it occur?
- Which compiler (+version) are you using (with what flags)?
- What are the steps to reproduce (i.e. does this e.g. happen 
with a main that consist of one call to EnumServices) ?


More information about the Digitalmars-d-learn mailing list