1 /* Copyright (C) 1990-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
21 #include <support/support.h>
28 char *lo_around
, *hi_around
;
32 int space_around
= 10;
36 mem
= xmalloc (max_size
+ 2 * max_size
+ 2 * space_around
);
37 rand_mem
= xmalloc (max_size
);
38 lo_around
= xmalloc (space_around
);
39 hi_around
= xmalloc (space_around
);
40 memp
= mem
+ space_around
;
42 /* Fill RAND_MEM with random bytes, each non-zero. */
43 for (i
= 0; i
< max_size
; i
++)
52 for (size
= 0; size
< max_size
; size
++)
54 printf("phase %d\n", size
);
55 for (src_off
= 0; src_off
<= 16; src_off
++)
57 for (dst_off
= 0; dst_off
<= 16; dst_off
++)
59 /* Put zero around the intended destination, to check
60 that it's not clobbered. */
61 for (i
= 1; i
< space_around
; i
++)
63 memp
[dst_off
- i
] = 0;
64 memp
[dst_off
+ size
- 1 + i
] = 0;
67 /* Fill the source area with known contents. */
68 for (i
= 0; i
< size
; i
++)
69 memp
[src_off
+ i
] = rand_mem
[i
];
71 /* Remember the contents around the destination area.
72 (It might not be what we wrote some lines above, since
73 the src area and the dst area overlap.) */
74 for (i
= 1; i
< space_around
; i
++)
76 lo_around
[i
] = memp
[dst_off
- i
];
77 hi_around
[i
] = memp
[dst_off
+ size
- 1 + i
];
80 memmove (memp
+ dst_off
, memp
+ src_off
, size
);
82 /* Check that the destination area has the same
83 contents we wrote to the source area. */
84 for (i
= 0; i
< size
; i
++)
86 if (memp
[dst_off
+ i
] != rand_mem
[i
])
90 /* Check that the area around the destination is not
92 for (i
= 1; i
< space_around
; i
++)
94 if (memp
[dst_off
- i
] != lo_around
[i
])
96 if (memp
[dst_off
+ size
- 1 + i
] != hi_around
[i
])
103 puts ("Test succeeded.");
108 #include <support/test-driver.c>