Knowledge Base Article

memcpy() Optimization Misalignment

Description

When optimization is turned on (-O1 or higher), if you use memcpy() and the source pointer is aligned to a 32-bit boundary, the compiler implements memcpy() with word-oriented instructions as part of the optimization process. This optimization technique causes unexpected results in your software if memcpy() is used on a misaligned address.

Resolution

Take steps to ensure that an optimized implementation of memcpy() is called only with aligned data pointers.

Updated 2 months ago
Version 3.0
No CommentsBe the first to comment