From: Nicholas Nethercote Date: Fri, 3 Sep 2004 14:04:40 +0000 (+0000) Subject: Avoid spurious warning about using posix_memalign() X-Git-Tag: svn/VALGRIND_3_0_0~1626 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eea34ddbd62908ad8f18a9469efc6e794b278dfd;p=thirdparty%2Fvalgrind.git Avoid spurious warning about using posix_memalign() git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2657 --- diff --git a/memcheck/tests/memalign2.c b/memcheck/tests/memalign2.c index c2d204b791..0da0b4f32a 100644 --- a/memcheck/tests/memalign2.c +++ b/memcheck/tests/memalign2.c @@ -1,3 +1,16 @@ + +// These #defines attempt to ensure that posix_memalign() is declared, and +// so no spurious warning is given about using it. + +// Advertise compliance of the code to the XSI (a POSIX superset that +// defines what a system must be like to be called "UNIX") +#undef _XOPEN_SOURCE +#define _XOPEN_SOURCE 600 + +// Advertise compliance to POSIX +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200112L + #include #include #include @@ -32,24 +45,25 @@ int main ( void ) p = memalign(4096, 100); assert(0 == (long)p % 4096); p = memalign(4097, 100); assert(0 == (long)p % 8192); - res = posix_memalign(&p, -1,100); assert(EINVAL == res); - res = posix_memalign(&p, 0, 100); assert(0 == res && 0 == (long)p % 8); - res = posix_memalign(&p, 1, 100); assert(EINVAL == res); - res = posix_memalign(&p, 2, 100); assert(EINVAL == res); - res = posix_memalign(&p, 3, 100); assert(EINVAL == res); - res = posix_memalign(&p, sizeof(void*), 100); - assert(0 == res && - 0 == (long)p % sizeof(void*)); - - res = posix_memalign(&p, 31, 100); assert(EINVAL == res); - res = posix_memalign(&p, 32, 100); assert(0 == res && + #define PM(a,b,c) posix_memalign((void**)a, b, c) + + res = PM(&p, -1,100); assert(EINVAL == res); + res = PM(&p, 0, 100); assert(0 == res && 0 == (long)p % 8); + res = PM(&p, 1, 100); assert(EINVAL == res); + res = PM(&p, 2, 100); assert(EINVAL == res); + res = PM(&p, 3, 100); assert(EINVAL == res); + res = PM(&p, sizeof(void*), 100); + assert(0 == res && 0 == (long)p % sizeof(void*)); + + res = PM(&p, 31, 100); assert(EINVAL == res); + res = PM(&p, 32, 100); assert(0 == res && 0 == (long)p % 32); - res = posix_memalign(&p, 33, 100); assert(EINVAL == res); + res = PM(&p, 33, 100); assert(EINVAL == res); - res = posix_memalign(&p, 4095, 100); assert(EINVAL == res); - res = posix_memalign(&p, 4096, 100); assert(0 == res && + res = PM(&p, 4095, 100); assert(EINVAL == res); + res = PM(&p, 4096, 100); assert(0 == res && 0 == (long)p % 4096); - res = posix_memalign(&p, 4097, 100); assert(EINVAL == res); + res = PM(&p, 4097, 100); assert(EINVAL == res); return 0; }