opnsense-src/lib/libc/tests/string/memset_test.c
Strahinja Stanišić f0d1236f0f libc: Add memset test for int-to-char conversion
Test case to check if an implementation of memset correctly
handles the value passed being wider than a byte

Approved by:	emaste
Reviewed By:	fuz (GSoC mentor), emaste
Sponsored by:	Google LLC (GSoC 2024)
Differential Revision: https://reviews.freebsd.org/D45738
2024-07-13 15:07:49 +02:00

29 lines
452 B
C

/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2024 Strahinja Stanisic <strajabot@FreeBSD.org>
*/
#include <assert.h>
#include <string.h>
#include <atf-c.h>
ATF_TC_WITHOUT_HEAD(int_char_conv);
ATF_TC_BODY(int_char_conv, tc)
{
char b[64];
int c = 0xDEADBEEF;
memset(&b, c, 64);
for(int i = 0; i < 64; i++) {
assert(b[i] == (char)c);
}
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, int_char_conv);
return (atf_no_error());
}