Thread: Memcopy

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    1

    Memcopy

    what would be happen if we copy the size of source more than the size of the destination using memcpy function


    unsigned short dst[128];

    unsigned short source[256];

    memcpy(dst, source, 1000);

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    memcpy starts writing to memory beyond the bounds of dest like nothing is wrong, which may or may not trigger a segmentation fault in response to the undefined behavior.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Buffer overrun.
    Why would you use memcpy in C++ anyway?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed