Overriding the Memmove function

Source: Internet
Author: User

In the case of memory duplication, if there are overlapping in two paragraphs, then it is easy to generate coverage. So rewrite this function to handle copies of overlapping memory.

void* memmove (void* str1,const void* str2,int N) {    char* pStr1 = (char*) str1;    Const char* PSTR2 = (const char*) str2;    if (PStr1 < PSTR2)//starting from the front copy{for        (int i=0; i!=n; ++i) {            * (pstr1++) = * (pstr2++);        }    }    else//starting from the back copy{        pStr1 + = n-1;        PSTR2 + = n-1;        for (int i=0; i!=n; ++i) {            * (pstr1--) = * (pstr2--);        }    }    return PSTR1;}

To avoid overwriting a memory area that has not yet been copied, the solution here is to copy the memory from the front or back, based on the location of the two pieces of memory.

Overriding the Memmove function

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.