Re: [exim] [BUG?] in src/auths/pwcheck.c

Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: Chris Lightfoot
Ημερομηνία:  
Προς: exim-users
Αντικείμενο: Re: [exim] [BUG?] in src/auths/pwcheck.c
On Thu, Oct 05, 2006 at 02:28:49PM +0100, Philip Hazel wrote:
> <aside>
> You can tell that this is not my code because I would have written "if
> (reply != NULL)" rather than "if (reply)". I feel uncomfortable assuming
> that NULL is the same as zero - even though every C system in the world
> does it this way, I think. The standard says that NULL "expands to an
> implementation-defined null pointer constant". It doesn't say it has to
> be zero when cast to an int. I only write "if (variable)" when the
> variable is known to be a Boolean true/false value. Even for an integer
> I'd write "if (x != 0)". It's a pity that C conflates Booleans and
> integers.
> </aside>


no -- you have the sense of the cast the wrong way round.
if you compare a pointer x to 0 with !=, then the 0 is
`cast to' a pointer having the same type as x (acts as
`null pointer constant' in the language of the standard).
Relevant references (from the C99 final committee draft
but I think these carry over to the real standard):

6.8.4.1.2
    if (x) ...
        is equivalent to
    if (x != 0) ...


6.3.2.3
    ``An integer expression with the value 0, or such an
    expression cast to type void*, is called a null
    pointer constant. If a null pointer constant is
    assigned to or compared for equality to a pointer, the
    constant is converted to a pointer of that type.''



Actually from a brief grep exim isn't free of assumptions
about the in-memory format of different objects. e.g.
demime.c does,

        memset(&mime_part_p,0,sizeof(mime_part));


to clear the contents of the struct mime_part mime_part_p.
(There are various other uses of memset(p, 0, sizeof *p)
but I didn't check whether the elements of the p include
pointers specifically.) Of course that assumes that the
appropriate zero or null value for each of the elements of
the struct is all-bits-zero. That's not necessarily true
(by which I mean, it's almost certainly true on every
platform where exim runs, but the C and POSIX standards
don't require that that be so). The ugly but proper way to
do that is,

    const struct mime_part mimez = {0};
        /* ... */
    mime_part_p = mimez;


but only nutters like me actually bother to write their
code this way....

--
``We are not knocking down doors at four in the morning with people
booted and suited in riot gear. Most of the removals occur around
half-five, half-six, seven in the morning.''
(Tony McNulty denies reports of `dawn raids' on asylum seekers)