1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*============================================================================
6**
7** Source: test1.c
8**
9** Purpose: Calls memcpy and verifies that the buffer was copied correctly.
10**
11**
12**==========================================================================*/
13
14#include <palsuite.h>
15
16int __cdecl main(int argc, char **argv)
17{
18 char testA[20];
19 char testB[20];
20 void *retVal;
21 long i;
22
23 if (PAL_Initialize(argc, argv))
24 {
25 return FAIL;
26 }
27
28
29 memset(testA, 'a', 20);
30 memset(testB, 'b', 20);
31
32 retVal = (char *)memcpy(testB, testA, 0);
33 if (retVal != testB)
34 {
35 Fail("memcpy should return a pointer to the destination buffer, "
36 "but doesn't.\n");
37 }
38 for(i = 0; i<20; i++)
39 {
40 if (testB[i]!= 'b')
41 {
42 Fail("The destination buffer overflowed by memcpy.\n");
43 }
44 }
45
46 retVal = (char *)memcpy(testB+1, testA, 18);
47 if (retVal != testB+1)
48 {
49 Fail("memcpy should return a pointer to the destination buffer, "
50 "but doesn't.\n");
51 }
52
53 if (testB[0] != 'b' || testB[19] != 'b')
54 {
55 Fail("The destination buffer was written out of bounds by memcpy!\n");
56 }
57
58 for(i = 1; i<19; i++)
59 {
60 if (testB[i]!= 'a')
61 {
62 Fail("The destination buffer copied to by memcpy doesn't match "
63 "the source buffer.\n");
64 }
65 }
66
67 PAL_Terminate();
68
69 return PASS;
70}
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88