tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: aligned_alloc c11 function
Date: Sat, 24 Oct 2015 19:42:45 +0200
From: Niclas Rosenvik <nros%NetBSD.org@localhost>
Message-ID: <20151024194245.58b090e0%NetBSD.org@localhost>
Also ...
| +ATF_TC_BODY(aligned_alloc_basic, tc)
| +{
| + size_t size[] = {
| + 1, 2, 3, 4, 10, 100, 16384, 32768, 65536, 10000
| + };
| + size_t align[] = {
| + 512, 1024, 16, 32, 64, 4, 2048, 16, 2, 2048
| + };
| +
| + size_t i;
| + void *p;
| +
| + for (i = 0; i < __arraycount(size); i++) {
| + p = (void*)0x1;
Useless assignment, delete it.
| +
| + (void)printf("Checking aligned_alloc(%zd, %zd)...\n",
| + align[i], size[i]);
| + p = aligned_alloc(align[i], size[i]);
| +
| + if ( align[i] < sizeof(void *) || size[i] % align[i] != 0 )
Check p == NULL as well, that's supposed to be the indicator of failure.
(And if my earlier suggestion is adopted, obviously skip the
first of those tests.)
The right way to test this is probably more like (pseudo-code, with meaningless
markup from the diff still left ...)
if (p == NULL) {
if (size[i] % align[i] != 0)
ATF_REQUIRE_EQ_MSG(errno, EINVAL,
| + "aligned_alloc: %s", strerror(errno));
else if (errno != ENOMEM)
/* something */
else /* message for ENOMEM in test ?? */
} else {
if (size[i] % align[i] != 0)
/* error message */
| + ATF_REQUIRE_EQ_MSG(((intptr_t)p) & (align[i]-1), 0,
| + "p = %p", p);
| + free(p);
| + }
| + }
| +}
Home |
Main Index |
Thread Index |
Old Index