Control effects on padding when copying a C++ POD
Padding is not specified in C++ standard. It is compiler and CPU
dependent. Manually avoid padding could lead to performance issues or
worse. So controlling what's in padding seems to be a more viable way to
minimize undesirable side effects caused by padding, such as security.
What I want to do is to have padding of zero in an aligned POD. e.g. a
templated function template<typename T> T zero_padding(T const & pod);
But there are problems.
If we do a direct struct copy, we don't know what will be done on padding,
since C standard doesn't guarantee anything.
We can memset the structure, and then do a member-wise copy. But it seems
to be structure-specific, and not easily done for template.
So I can't seem to find an easy way to do this.
No comments:
Post a Comment