On Mon, Dec 01, 2014 at 06:13:04PM -0800, Kevin J. McCarthy wrote:
> > Returning NULL from something that allocates memory is always a good
> > (and I dare say the best) option.  
[...]
> Note that mutt's safe_malloc() exits the program when an allocation
> error occurs though.

...excepting the case where the requested size of the memory being
allocated is zero.  In that case, it returns NULL (well, zero, but
close enough--I'd prefer it actually returned NULL so the intention is
more clear, but that's mostly a style point).  

Note that this behavior is probably the Wrong Thing™, since it appears
that the point of safe_malloc is to make sure that it never returns
NULL, so that the caller need never check the return value.  Certainly
that assumption was made in the code in mutt_substrdup()...  Thus that
function should probably also exit in that case, though with a
different error message to distinguish the case.  I would argue that
such a case is clearly a bug, so it should probably abort() to produce
a core dump.

Likewise, mutt_substrdup() should check its arguments to make sure
they can not produce a string of size less than 0, and abort if they
would.

Regarding SKIPWS() / skip_email_wsp():

It seems to me that there are only two cases here: one where mutt
should only skip ' ' and '\t', and another where it should skip all
whitespace in the current locale.  So seems to me this could be solved
by defining skip_email_wsp() as:

#define EMAIL_WSP " \t"

/* s must be returned non-const; skip const and skip the casts */
static inline char *skip_email_wsp(char *s, int strict_space)
{
    if (!s) return s;
    if (strict_space) return s + strspan(s, EMAIL_WSP);
    while (*s && isspace((unsigned char)*s)) s++;
    return s;
}

Then just call skip_email_wsp with the right flag value for the case
you're dealing with, i.e. 1 for rfc822.c and sendlib.c, and 0
otherwise.

-- 
Derek D. Martin    http://www.pizzashack.org/   GPG Key ID: 0xDFBEAD02
-=-=-=-=-
This message is posted from an invalid address.  Replying to it will result in
undeliverable mail due to spam prevention.  Sorry for the inconvenience.

Attachment: pgpZCoe_rtG7o.pgp
Description: PGP signature

Reply via email to