Given the following code, is it legal in C? (C89, C99, and so on?)
DATA_STRUCT *ptr;
ptr = malloc(sizeof(*ptr) + 400);
memset(ptr, 0, sizeof(*ptr)); // clearing only the structure itself (not the 400 additional bytes).
I'm aware of VLA and sizeof being evaluated at run-time, but for all other cases, is it always at compile-time?
EDIT: From the answers I see this may be caused by:
- A compiler bug
- A heap corruption
1 seems sorta unlikely, so I'm leaning towards 2. Either way, this needs to be further investigated.