[patch] bus error in gcry_free

Werner Koch wk at gnupg.org
Thu Feb 1 16:55:00 CET 2007

On Thu,  1 Feb 2007 16:24, christianbiere at gmx.de said:

>>   return (pool_okay
>>           && p >= pool
>>           && p < (const void*)((const char*)pool+pool_size));
> If p points into the pool or just one byte after it, everything is fine and
> well-defined. Otherwise, the behaviour of this code is completely undefined.
> A compile may optimize this into this:
>    return pool_okay && p != (const void*)((const char*)pool+pool_size);

Sorry, I may be temporary blind but I can't see how you come to this
conclusion.  What is wrong with:

  (const void*) ((const char*)pool + pool_size)
                 =================   =========
                  So that we can     And add the size
                  do pointer         of the pool
                Yielding a pointer right behind POOL
  Casting it to void* for proper comparing against P

?  How can the comparison be optimized away?

> Then you've been GCCed. pointer arithmetic with "void *" is not covered by
> any C standard and usually GCC warns about this.

Damned, forgot to enable the extra gcc warnings.  I knew that there
must have been some reason that I originally casted it.  That happens if
you rely too much on warnings :-(



More information about the Gcrypt-devel mailing list