Export (0) Print
Expand All
div
eof
Expand Minimize
0 out of 2 rated this helpful - Rate this topic

memmove_s, wmemmove_s 

Moves one buffer to another. These are versions of memmove, wmemmove with security enhancements as described in Security Enhancements in the CRT.


errno_t memmove_s(
   void *dest,
   size_t numberOfElements,
   const void *src,
   size_t count 
);
errno_t wmemmove_s(
   wchar_t *dest,
   size_t numberOfElements,
   const wchar_t *src,
   size_t count
);

Parameters

dest

Destination object.

numberOfElements

Size of the destination buffer.

src

Source object.

count

Number of bytes of characters to copy.

Zero if successful; an error code on failure

Error Conditions
dest numberOfElements src Return value Contents of dest

NULL

any

any

EINVAL

not modified

any

any

NULL

EINVAL

not modified

any

< count

any

ERANGE

not modified

Copies count bytes of characters from src to dest. If some regions of the source area and the destination overlap, memmove_s ensures that the original source bytes in the overlapping region are copied before being overwritten.

If dest or if src is a null pointer, or if the destination string is too small, these functions invoke an invalid parameter handler, as described in Parameter Validation . If execution is allowed to continue, these functions return EINVAL and set errno to EINVAL.

Routine Required header Compatibility

memmove_s

<string.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

wmemmove_s

<wchar.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For additional compatibility information, see Compatibility in the Introduction.

// crt_memmove_s.c
//
// The program demonstrates the 
// memmove_s function which works as expected
// for moving overlapping regions.

#include <stdio.h>
#include <string.h>

int main()
{
   char *str = "0123456789";

   printf("Before: %s\n", str);

   // Move six bytes from the start of the string
   // to a new position shifted by one byte. To protect against
   // buffer overrun, the secure version of memmove requires the
   // the length of the destination string to be specified. 

   memmove_s((str + 1), strnlen(str + 1, 10), str, 6); 

   printf_s(" After: %s\n", str);
}
Before: 0123456789
 After: 0012345789

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.