-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Hernan Ponce de Leon <[email protected]> Co-authored-by: Hernan Ponce de Leon <[email protected]>
- Loading branch information
1 parent
016aaf4
commit 184fab4
Showing
4 changed files
with
622 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <assert.h> | ||
#include <stddef.h> | ||
|
||
#ifdef __STDC_LIB_EXT1__ | ||
#define __STDC_WANT_LIB_EXT1__ 1 | ||
#include <string.h> | ||
#else | ||
#define rsize_t size_t | ||
#define errno_t int | ||
extern errno_t memcpy_s( void *restrict dest, rsize_t destsz, const void *restrict src, rsize_t count ); | ||
#endif | ||
|
||
int main() | ||
{ | ||
int a[4] = { 1, 2, 3, 4 }; | ||
int b[3] = { 5, 6, 7}; | ||
|
||
int ret; | ||
|
||
// NULL dest | ||
ret = memcpy_s(NULL, 3*sizeof(int), a, 3*sizeof(int)); | ||
assert(ret > 0); | ||
|
||
// NULL src | ||
ret = memcpy_s(b, 3*sizeof(int), NULL, 3*sizeof(int)); | ||
assert(ret > 0); | ||
assert(b[0] == 0); | ||
assert(b[1] == 0); | ||
assert(b[2] == 0); | ||
b[0] = 5; | ||
b[1] = 6; | ||
b[2] = 7; | ||
|
||
// count > destsz | ||
ret = memcpy_s(b, 2*sizeof(int), a, 4*sizeof(int)); | ||
assert(ret > 0); | ||
assert(b[0] == 0); | ||
assert(b[1] == 0); | ||
// only [dest, dest+destsz) is zeroed | ||
assert(b[2] == 7); | ||
b[0] = 5; | ||
b[1] = 6; | ||
|
||
// Overlapping src and dest | ||
ret = memcpy_s(b, 3*sizeof(int), b, 3*sizeof(int)); | ||
assert(ret > 0); | ||
assert(b[0] == 0); | ||
assert(b[1] == 0); | ||
assert(b[2] == 0); | ||
b[0] = 5; | ||
b[1] = 6; | ||
b[2] = 7; | ||
|
||
// Success | ||
ret = memcpy_s(b, 3*sizeof(int), a, 3*sizeof(int)); | ||
assert(ret == 0); | ||
assert(b[0] == 1); | ||
assert(b[1] == 2); | ||
assert(b[2] == 3); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.