|
From: Tom H. <th...@cy...> - 2003-11-27 23:55:27
|
In message <3FC...@bc...>
Andriy Rysin <ar...@bc...> wrote:
> #include <stdio.h>
> #include <stdlib.h>
>
> int main()
> {
> char* p = 0;
> int ret = posix_memalign(&p, 16, 800*600*3/2);
> printf("ret %d, p %p\n", ret, p);
>
> return 0;
> }
>
> # ./test
> ret 0, p 0xbf4f8020
>
> # valgrind ./test
> ==28692== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
> ==28692== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward.
> ==28692== Using valgrind-2.0.0, a program supervision framework for
> x86-linux.
> ==28692== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward.
> ==28692== Estimated CPU clock rate is 2025 MHz
> ==28692== For more details, rerun with: -v
> ==28692==
> ret 22, p (nil)
It looks like this is caused by this condition in valgrind's
version of posix_memalign:
/* Test whether the SIZE argument is valid. It must be a power of
two multiple of sizeof (void *). */
if (size % sizeof (void *) != 0 || (size & (size - 1)) != 0)
return VKI_EINVAL /*22*/ /*EINVAL*/;
Specifically by the second half of the or condition, which doesn't
seem to make any sense to me.
In fact, according to the manual page, it is the alignment parameter
that is supposed to be subject to the constraints on being a multiple
of the size of void * and being a power of two.
Tom
--
Tom Hughes (th...@cy...)
Software Engineer, Cyberscience Corporation
http://www.cyberscience.com/
|