First, describe
The bug is now found in the linux64 bit system under g++4.4.7. The other versions have not yet been tested.
It is tested that a segment error is bound to occur if the address of the first parameter (that is, the target buffer) passed into the wcsncpy function is not divisible by 4.
After debugging, the function assembly code is used to the MOVDQA instruction, which requires that the parameters must be memory-aligned, if the parameter (target buffer) is not memory-aligned, it will cause a segment error.
Second, the test code
#include <wchar.h> #pragma pack (1) struct kom{ char c; wchar_t s[32];}; #pragma pack () int main (int argc, char** argv) { Kom Kom; Const wchar_t* k = L "Kom"; wcsncpy (KOM.S, K, sizeof (KOM.S)/sizeof (kom.s[0])); return 0;}
Linux64 bit system g++4.4.7 using wcsncpy function has a bug that causes a segment error (other g++ version unknown)