Today at work I encountered the following warning in release mode:
warning C4789: destination of memory copy is too small
The errant line was a standard function call - nothing crazy going on. For the sake of argument the function did something of the form:
GetValueByName("name of value", &OutputValue);
The function is declared GetValueByName(const char*, void*), and in the function it looked something like this:
ValueDescriptor Desc = FindValueDescriptor(PassedInNameOfValue);
return GetValueByDesc(Desc, PtrToOutputValue);
GetValueByDesc() worked somewhat like:
switch (Descriptor.Value)
case SomeFloatProperty: *(float*)PtrToOutputValue = MyFloatProperty;
case SomeVectorProperty: *(vector*)PtrToOutputValue = MyVectorProperty;
..etc..
This had been working for months (years actually) without error. And now when we compile in release, we get the aforementioned warning.
The compiler, as it happens, decided on this one callsite to inline *both* levels, and drop the switch statement in to the caller. As a result, in the code generation, there was a case that could write 12 bytes (via the vector dereference) to the output pointer, which triggered the warning.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment