[PATCH] json: Avoid calling strlen(NULL)

Carl Worth cworth at cworth.org
Tue Apr 20 08:59:52 PDT 2010


> There's already a check in json_quote_chararray for len==0, so it
> might be sensible to say:
> 
>     return (json_quote_chararray (ctx, str, str != NULL ? strlen (str) : 0));
> 
> OTOH, the code in json_quote_array to deal with that does the same
> thing (returns a literal string containing two quote marks), which
> seems wrong -- the normal code path is to talloc to get a newly
> allocated, editable string, that might be talloc_free'd later,
> wouldn't it make more sense just to let the str==NULL / len==0
> behaviour fall through into the normal case code?

Yes, that's the correct analysis. Thanks so much.

> commit 5b93a488221b50c02db18d86a550cb3c038c00da
> Author: Anthony <aj at erisian.com.au>
> Date:   Tue Apr 6 18:10:39 2010 +1000
> 
>     json: Avoid calling strlen(NULL), and always return a newly
>     talloced array.


I've pushed this out now, (separated into two pieces).

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20100420/8b505c7f/attachment.pgp>


More information about the notmuch mailing list