Memory reallocation changes the originally stricter alignment of an object
This defect occurs when you
use realloc() to modify the size of objects with strict memory alignment
requirements.
The pointer returned by realloc() can be suitably assigned to objects
with less strict alignment requirements. A misaligned memory allocation can lead to buffer
underflow or overflow, an illegally dereferenced pointer, or access to arbitrary memory
locations. In processors that support misaligned memory, the allocation impacts the
performance of the system.
To reallocate memory:
Resize the memory block.
In Windows®, use _aligned_realloc() with the alignment
argument used in _aligned_malloc() to allocate the original
memory block.
In UNIX/Linux, use the same function with the same alignment argument used to allocate the original memory block.
Copy the original content to the new memory block.
Free the original memory block.
Note
This fix has implementation-defined behavior. The implementation might not support the requested memory alignment and can have additional constraints for the size of the new memory.
| Group: Dynamic memory |
| Language: C | C++ |
| Default: On for handwritten code, off for generated code |
Command-Line Syntax:
ALIGNMENT_CHANGE
|
| Impact: Low |