3 ms·
Many Microsoft APIs do that so that they can add members at the end of the struct in future versions. Inside the implementation of the API they might say:
by asveikau 7y ago
Many Microsoft APIs do that so that they can add members at the end of the struct in future versions.
Inside the implementation of the API they might say:
if (wndClass->cbSize == SIZE_IN_PREVIOUS_SDK_VERSION)
{
// Code to handle legacy structure goes here
}
If they add to the struct and don't make accesses to the new members conditional on cbSize's value, then it's a bad pointer dereference. The caller allocated it with the "old" size, likely on their stack, and some unrelated value might be located where the new members would be, or it could be a bad pointer.