[Solved] pointer and 0xDEADBEEF, why does this code not work? [closed]


Based on the threads Ive read on here, setting a pointer to deadbeef will make the pointer null.

No, that is incorrect. Although deadbeef is a common “nonsense pattern”, it is definitely not equal null. A common reason to set pointers (more generally, a memory area) to a known and unusual pattern, such as deadbeef, is to detect non-initialized areas of memory. A pattern of all zeros, which is commonly used to represent null pointers, is not as good a candidate, because your chances of finding a sequence of zeros in consecutive memory locations is much higher than finding a sequence of deadbeefs.

The crash that you see in the call of strcpy happens because secondpointer is set to an invalid value. You need to allocate enough memory to fit "Here is some text, here is some more", along with its terminating zero, in order for strcpy not to exhibit undefined behavior.

5

solved pointer and 0xDEADBEEF, why does this code not work? [closed]