mirror of
https://git.savannah.gnu.org/git/gnulib.git
synced 2026-10-24 00:48:56 +03:00
* tests/test-wmemcpy.c (null_wmemcpy, main): Move the #if and comment from null_wmemcpy to main to avoid invoking undefined behavior. * tests/test-wmemmove.c (null_wmemmove, main): Likewise.
72 lines
2.1 KiB
C
72 lines
2.1 KiB
C
/* Test of wmemmove() function.
|
|
Copyright (C) 2024-2026 Free Software Foundation, Inc.
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
|
|
#include <config.h>
|
|
|
|
/* Specification. */
|
|
#include <wchar.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include "macros.h"
|
|
|
|
/* Test the prototype in <wchar.h> + compiler. */
|
|
static wchar_t *
|
|
null_wmemmove (wchar_t *s1, wchar_t const *s2, size_t n)
|
|
{
|
|
wchar_t *p = wmemmove (s1, s2, n);
|
|
ASSERT (s1 == NULL);
|
|
return p;
|
|
}
|
|
static wchar_t *(*volatile volatile_null_wmemmove) (wchar_t *, wchar_t const *,
|
|
size_t)
|
|
= null_wmemmove;
|
|
|
|
/* Test the library, not the compiler+library. */
|
|
static wchar_t *
|
|
lib_wmemmove (wchar_t *s1, wchar_t const *s2, size_t n)
|
|
{
|
|
return wmemmove (s1, s2, n);
|
|
}
|
|
static wchar_t *(*volatile volatile_lib_wmemmove) (wchar_t *, wchar_t const *,
|
|
size_t)
|
|
= lib_wmemmove;
|
|
#undef wmemmove
|
|
#define wmemmove volatile_lib_wmemmove
|
|
|
|
int
|
|
main (void)
|
|
{
|
|
/* Test zero-length operations on NULL pointers, allowed by
|
|
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.
|
|
In mingw-w64 14.0.0, wmemmove is an inline function that calls memmove.
|
|
In GCC < 15, memmove is a builtin that has the nonnull attribute. */
|
|
|
|
#if ! (defined __MINGW32__ \
|
|
&& defined __GNUC__ && !defined __clang__ && __GNUC__ < 15)
|
|
ASSERT (wmemmove (NULL, L"x", 0) == NULL);
|
|
|
|
{
|
|
wchar_t y[1];
|
|
ASSERT (wmemmove (y, NULL, 0) == y);
|
|
}
|
|
|
|
ASSERT (volatile_null_wmemmove (NULL, L"x", 0) == NULL);
|
|
#endif
|
|
|
|
return test_exit_status;
|
|
}
|