Memcopy

This is a discussion on Memcopy within the C++ Programming forums, part of the General Programming Boards category; what would be happen if we copy the size of source more than the size of the destination using memcpy ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,656
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21