Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 37 / e38a863c08ef164a2d856ffac29358697723b9
1 Return-Path: <anthony.j.towns@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 412034196F4\r
6         for <notmuch@notmuchmail.org>; Tue,  6 Apr 2010 01:17:46 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
12         tests=[BAYES_40=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,\r
13         FREEMAIL_FROM=0.001] autolearn=ham\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id VQU35p0RkO+t for <notmuch@notmuchmail.org>;\r
17         Tue,  6 Apr 2010 01:17:45 -0700 (PDT)\r
18 Received: from mail-gy0-f181.google.com (mail-gy0-f181.google.com\r
19         [209.85.160.181])\r
20         by olra.theworths.org (Postfix) with ESMTP id 720624196F0\r
21         for <notmuch@notmuchmail.org>; Tue,  6 Apr 2010 01:17:45 -0700 (PDT)\r
22 Received: by gyg8 with SMTP id 8so2575952gyg.26\r
23         for <notmuch@notmuchmail.org>; Tue, 06 Apr 2010 01:17:45 -0700 (PDT)\r
24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
25         h=domainkey-signature:mime-version:sender:received:in-reply-to\r
26         :references:date:x-google-sender-auth:received:message-id:subject\r
27         :from:to:cc:content-type:content-transfer-encoding;\r
28         bh=3FVGXrclAGAnpw3LKZdskcykb3kM88DoLZCssAe5OMk=;\r
29         b=jORJdZGsLov5yydErhTCRl1Mdi2xD/qnquf1IPqbnffCBExwbw0t8zp9qSoG2JsnKy\r
30         XZcQVN+m7xfhiuDC289FHslq9B2oL8lgmXtqQTL2xfzJtIQLu48EqB2h5eodf5CpKykp\r
31         5UjboIVrtWb4aWy57I4sw2OWjwTRmKqHFN1+k=\r
32 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;\r
33         h=mime-version:sender:in-reply-to:references:date\r
34         :x-google-sender-auth:message-id:subject:from:to:cc:content-type\r
35         :content-transfer-encoding;\r
36         b=cWrH6GQNIqcF1OuqlliWtkaTOYti1pwcB532p1bY7H5wpGUkpq04ZT/erCITvBnEuM\r
37         xi/ss0/UZzMsEHXDOQjHHDM6a9vd01LjpkNryr9NxUci1YG5ylkJqDfOaI5iK6d+P8Yn\r
38         v7nqKhdyCxOMxH+HTJOofwBQDNL2KGroUxDh4=\r
39 MIME-Version: 1.0\r
40 Sender: anthony.j.towns@gmail.com\r
41 Received: by 10.90.114.1 with HTTP; Tue, 6 Apr 2010 01:17:44 -0700 (PDT)\r
42 In-Reply-To: <877holavq5.fsf@ut.hh.sledj.net>\r
43 References: <877holavq5.fsf@ut.hh.sledj.net>\r
44 Date: Tue, 6 Apr 2010 18:17:44 +1000\r
45 X-Google-Sender-Auth: d62a4c2bd810c785\r
46 Received: by 10.91.154.4 with SMTP id g4mr1172925ago.26.1270541864873; Tue, 06\r
47         Apr 2010 01:17:44 -0700 (PDT)\r
48 Message-ID: <h2y87b3a4191004060117v5421db8ejbe3030d0626e7440@mail.gmail.com>\r
49 Subject: Re: [PATCH] json: Avoid calling strlen(NULL)\r
50 From: Anthony Towns <aj@erisian.com.au>\r
51 To: David Edmondson <dme@dme.org>\r
52 Content-Type: text/plain; charset=ISO-8859-1\r
53 Content-Transfer-Encoding: quoted-printable\r
54 Cc: notmuch <notmuch@notmuchmail.org>\r
55 X-BeenThere: notmuch@notmuchmail.org\r
56 X-Mailman-Version: 2.1.13\r
57 Precedence: list\r
58 List-Id: "Use and development of the notmuch mail system."\r
59         <notmuch.notmuchmail.org>\r
60 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
62 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
63 List-Post: <mailto:notmuch@notmuchmail.org>\r
64 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
65 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
67 X-List-Received-Date: Tue, 06 Apr 2010 08:17:46 -0000\r
68 \r
69 On Tue, Apr 6, 2010 at 17:25, David Edmondson <dme@dme.org> wrote:\r
70 > =A0 =A0json: Avoid calling strlen(NULL)\r
71 > =A0 =A0MIME parts may have no filename, which previously resulted in call=\r
72 ing\r
73 > =A0 =A0strlen(NULL).\r
74 > =A0char *\r
75 > =A0json_quote_str(const void *ctx, const char *str)\r
76 > =A0{\r
77 > + =A0 =A0if (str =3D=3D NULL)\r
78 > + =A0 =A0 =A0 return (char *)"\"\"";\r
79 > +\r
80 > =A0 =A0 return (json_quote_chararray (ctx, str, strlen (str)));\r
81 > =A0}\r
82 \r
83 There's already a check in json_quote_chararray for len=3D=3D0, so it\r
84 might be sensible to say:\r
85 \r
86     return (json_quote_chararray (ctx, str, str !=3D NULL ? strlen (str) : =\r
87 0));\r
88 \r
89 OTOH, the code in json_quote_array to deal with that does the same\r
90 thing (returns a literal string containing two quote marks), which\r
91 seems wrong -- the normal code path is to talloc to get a newly\r
92 allocated, editable string, that might be talloc_free'd later,\r
93 wouldn't it make more sense just to let the str=3D=3DNULL / len=3D=3D0\r
94 behaviour fall through into the normal case code?\r
95 \r
96 FWIW:\r
97 \r
98 commit 5b93a488221b50c02db18d86a550cb3c038c00da\r
99 Author: Anthony <aj@erisian.com.au>\r
100 Date:   Tue Apr 6 18:10:39 2010 +1000\r
101 \r
102     json: Avoid calling strlen(NULL), and always return a newly talloced ar=\r
103 ray.\r
104 \r
105     MIME parts may have a no filename, which causes json_quote_str()\r
106 to be invoked\r
107     with NULL instead of a string.\r
108 \r
109 diff --git a/json.c b/json.c\r
110 index f90b0fa..5e379ef 100644\r
111 --- a/json.c\r
112 +++ b/json.c\r
113 @@ -57,9 +57,6 @@ json_quote_chararray(const void *ctx, const char\r
114 *str, const size_t len)\r
115      size_t loop;\r
116      size_t required;\r
117 \r
118 -    if (len =3D=3D 0)\r
119 -       return (char *)"\"\"";\r
120 -\r
121      for (loop =3D 0, required =3D 0, ptr =3D str;\r
122          loop < len;\r
123          loop++, required++, ptr++) {\r
124 @@ -105,5 +102,8 @@ json_quote_chararray(const void *ctx, const char\r
125 *str, const size_t len)\r
126  char *\r
127  json_quote_str(const void *ctx, const char *str)\r
128  {\r
129 +    if (str =3D=3D NULL)\r
130 +        str =3D "";\r
131 +\r
132      return (json_quote_chararray (ctx, str, strlen (str)));\r
133  }\r
134 \r
135 \r
136 \r
137 --=20\r
138 Anthony Towns <aj@erisian.com.au>\r