NULL need not be all bits 0
Werner Koch
wk@gnupg.org
Mon, 25 Oct 1999 19:05:34 +0200
"D. Hugh Redelmeier" <hugh@mimosa.com> writes:
> It is a little known fact that the representation of a NULL of a
> particular pointer type may not have all bits 0. So clearing a chunk
I have never seen such an architecure but I am usually aware of this.
AfAIK, the standard says that (char*)0 will be evaluated as false in
an expression and storing a 0 into a char* will result in storing
the machines representation of a NULL-pointer. This ends up that we
don't have to care about it when writing C code ...
> gnupg-1.0.0/mpi/mpi-mpow.c" line 90:
> G = m_alloc_clear( (1<<k) * sizeof *G );
But sure, you are right here - in this case the compiler can't know
that we are going to store 0s in some pointers.
> The code assumes that this initializes an array of MPI pointers to
> NULL. This works on almost all machines, but is not guaranteed to
> work by the C standard.
Okay, so we better do:
G = m_alloc( (1<<k) * sizeof *G );
for(i=0; i < (1<<k); i++ )
g[i] = NULL; /* or 0 */
or use a special m_alloc_clear_array_of_type_G(). I some vendor
builds such a machine he probably has the resources to fic most
software :-)
You will probably find out that I also assume that a byte has 8 bits
;-)
Werner
--
Werner Koch at guug.de www.gnupg.org keyid 621CC013