Linux64 bit system g++4.4.7 using wcsncpy function has a bug that causes a segment error (other g++ version unknown)

Source: Internet
Author: User
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.