Re: notmuch and "mute" -- useful to anyone?
[notmuch-archives.git] / 0d / 9986be104d4981079f141c821a1c99839eb139
1 Return-Path: <amdragon@mit.edu>\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 76588431FAF\r
6         for <notmuch@notmuchmail.org>; Thu, 20 Dec 2012 18:04:03 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id pBTTMiRn5gUr for <notmuch@notmuchmail.org>;\r
16         Thu, 20 Dec 2012 18:04:03 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
18         [18.9.25.15])\r
19         by olra.theworths.org (Postfix) with ESMTP id CFB6E431FAE\r
20         for <notmuch@notmuchmail.org>; Thu, 20 Dec 2012 18:04:02 -0800 (PST)\r
21 X-AuditID: 1209190f-b7f016d000000e07-6d-50d3c39134a2\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id FA.64.03591.193C3D05; Thu, 20 Dec 2012 21:04:01 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id qBL240r2027304; \r
27         Thu, 20 Dec 2012 21:04:00 -0500\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBL23w0s003488\r
32         (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
33         Thu, 20 Dec 2012 21:03:59 -0500 (EST)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1Tlrxu-0007Ku-IZ; Thu, 20 Dec 2012 21:03:58 -0500\r
37 Date: Thu, 20 Dec 2012 21:03:58 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: david@tethera.net\r
40 Subject: Re: [PATCH 2/3] util: add xtalloc.[ch]\r
41 Message-ID: <20121221020358.GR6187@mit.edu>\r
42 References: <1355714648-23144-1-git-send-email-david@tethera.net>\r
43         <1355714648-23144-3-git-send-email-david@tethera.net>\r
44 MIME-Version: 1.0\r
45 Content-Type: text/plain; charset=us-ascii\r
46 Content-Disposition: inline\r
47 In-Reply-To: <1355714648-23144-3-git-send-email-david@tethera.net>\r
48 User-Agent: Mutt/1.5.21 (2010-09-15)\r
49 X-Brightmail-Tracker:\r
50  H4sIAAAAAAAAA+NgFupmleLIzCtJLcpLzFFi42IRYrdT1514+HKAQcMGFYuNy34yW9xo7Wa0\r
51         uH5zJrMDs8evtrnMHs9W3WL22HLoPXMAcxSXTUpqTmZZapG+XQJXxoStW9kLFolXLLz3ha2B\r
52         cY1QFyMnh4SAicSGpReZIWwxiQv31rOB2EIC+xglFr5k6mLkArI3MEpMujCTHcK5yCTRfe0M\r
53         C4SzhFGi/UcDWDuLgKrEkb/HwdrZBDQktu1fzghiiwiISpzeNIkVxGYWsJdYNHsS0CQODmEB\r
54         fYnPH+1ATF4BbYmFv7UgFldK7Pu/gR3E5hUQlDg58wkLRKeWxI1/IAdxANnSEsv/cYCEOQWc\r
55         JKb/2gg2XFRARWLKyW1sExiFZiHpnoWkexZC9wJG5lWMsim5Vbq5iZk5xanJusXJiXl5qUW6\r
56         Jnq5mSV6qSmlmxhBYc4pyb+D8dtBpUOMAhyMSjy8ERaXA4RYE8uKK3MPMUpyMCmJ8urtBwrx\r
57         JeWnVGYkFmfEF5XmpBYfYpTgYFYS4X2+BCjHm5JYWZValA+TkuZgURLnvZpy019IID2xJDU7\r
58         NbUgtQgmK8PBoSTBO+8QUKNgUWp6akVaZk4JQpqJgxNkOA/Q8OkgNbzFBYm5xZnpEPlTjIpS\r
59         4rztIAkBkERGaR5cLywNvWIUB3pFmFcdpIoHmMLgul8BDWYCGhykdwFkcEkiQkqqgTGYb73y\r
60         oilLp00+tTHRKvuUcu6eRxrdjI+VP8+/URkTs+tGxK63XGlRR23Y5Np58rYWb+BOmyW6/CXL\r
61         sWP+NocCDBd4ycyL5P94I+lAxilzAXHW7bM/TRdp+KBuVHgxMfJzRoP/8yXF+3v1khqunju3\r
62         f3a1pu2yNZ/b6l5bxqdYtD1dtkjH67USS3FGoqEWc1FxIgDsMh1wHgMAAA==\r
63 Cc: notmuch@notmuchmail.org, David Bremner <bremner@debian.org>\r
64 X-BeenThere: notmuch@notmuchmail.org\r
65 X-Mailman-Version: 2.1.13\r
66 Precedence: list\r
67 List-Id: "Use and development of the notmuch mail system."\r
68         <notmuch.notmuchmail.org>\r
69 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
71 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
72 List-Post: <mailto:notmuch@notmuchmail.org>\r
73 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
74 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
75         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
76 X-List-Received-Date: Fri, 21 Dec 2012 02:04:03 -0000\r
77 \r
78 Quoth david@tethera.net on Dec 16 at 11:24 pm:\r
79 > From: David Bremner <bremner@debian.org>\r
80\r
81 > These are intended to be simple wrappers to provide slightly better\r
82 > debugging information than what talloc currently provides natively.\r
83 > ---\r
84 >  notmuch-client.h    |    2 +-\r
85 >  util/Makefile.local |    2 +-\r
86 >  util/xtalloc.c      |   15 +++++++++++++++\r
87 >  util/xtalloc.h      |   18 ++++++++++++++++++\r
88 >  4 files changed, 35 insertions(+), 2 deletions(-)\r
89 >  create mode 100644 util/xtalloc.c\r
90 >  create mode 100644 util/xtalloc.h\r
91\r
92 > diff --git a/notmuch-client.h b/notmuch-client.h\r
93 > index d7b352e..60be030 100644\r
94 > --- a/notmuch-client.h\r
95 > +++ b/notmuch-client.h\r
96 > @@ -58,7 +58,7 @@ typedef GMimeCipherContext notmuch_crypto_context_t;\r
97 >  #include <errno.h>\r
98 >  #include <signal.h>\r
99 >  \r
100 > -#include <talloc.h>\r
101 > +#include "xtalloc.h"\r
102 >  \r
103 >  #define unused(x) x __attribute__ ((unused))\r
104 >  \r
105 > diff --git a/util/Makefile.local b/util/Makefile.local\r
106 > index a11e35b..8a62c00 100644\r
107 > --- a/util/Makefile.local\r
108 > +++ b/util/Makefile.local\r
109 > @@ -4,7 +4,7 @@ dir := util\r
110 >  extra_cflags += -I$(srcdir)/$(dir)\r
111 >  \r
112 >  libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \\r
113 > -               $(dir)/string-util.c\r
114 > +               $(dir)/string-util.c $(dir)/xtalloc.c\r
115 >  \r
116 >  libutil_modules := $(libutil_c_srcs:.c=.o)\r
117 >  \r
118 > diff --git a/util/xtalloc.c b/util/xtalloc.c\r
119 > new file mode 100644\r
120 > index 0000000..22834bd\r
121 > --- /dev/null\r
122 > +++ b/util/xtalloc.c\r
123 > @@ -0,0 +1,15 @@\r
124 > +#include <string.h>\r
125 > +#include "xtalloc.h"\r
126 > +\r
127 > +char *\r
128 > +xtalloc_strndup_named_const (void *ctx, const char *str,\r
129 > +                          size_t len, const char *name)\r
130 > +{\r
131 > +    char *ptr = talloc_named_const (ctx, len + 1, name);\r
132 > +\r
133 > +    if (ptr) {\r
134 > +     memcpy (ptr, str, len);\r
135 \r
136 This isn't safe.  If the string at ptr is actually shorter than len,\r
137 this may read past allocated memory and crash.\r
138 \r
139 Maybe this should just call talloc_strndup and talloc_set_name_const?\r
140 \r
141 > +     *(ptr + len) = '\0';\r
142 > +    }\r
143 > +    return ptr;\r
144 > +}\r
145 > diff --git a/util/xtalloc.h b/util/xtalloc.h\r
146 > new file mode 100644\r
147 > index 0000000..3cc1179\r
148 > --- /dev/null\r
149 > +++ b/util/xtalloc.h\r
150 > @@ -0,0 +1,18 @@\r
151 > +#ifndef _XTALLOC_H\r
152 > +#define _XTALLOC_H\r
153 > +\r
154 > +#include <talloc.h>\r
155 > +\r
156 > +/* Like talloc_strndup, but take an extra parameter for the internal talloc\r
157 > + * name (for debugging) */\r
158 > +\r
159 > +char *\r
160 > +xtalloc_strndup_named_const (void *ctx, const char *str,\r
161 > +                          size_t len, const char *name);\r
162 \r
163 I agree with Tomi that these shouldn't be named with 'x'.  For this\r
164 one, it seems fine to simply drop the 'x', since the name is fully\r
165 descriptive of what it does.\r
166 \r
167 > +\r
168 > +/* use the __location__ macro from talloc.h to name a string according to its\r
169 > + * source location */\r
170 > +\r
171 > +#define xtalloc_strndup(ctx, str, len) xtalloc_strndup_named_const (ctx, str, len, __location__)\r
172 \r
173 For this, what about talloc_strndup_debug?\r
174 \r
175 > +\r
176 > +#endif\r