Re: [PATCH 1/2] Annotate internal_error with the attribute noreturn
authorTomi Ollila <tomi.ollila@iki.fi>
Sat, 22 Sep 2012 20:03:40 +0000 (23:03 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:49:34 +0000 (09:49 -0800)
3d/04d2995232255de5ff5883bb0b25840b3f7cb5 [new file with mode: 0644]

diff --git a/3d/04d2995232255de5ff5883bb0b25840b3f7cb5 b/3d/04d2995232255de5ff5883bb0b25840b3f7cb5
new file mode 100644 (file)
index 0000000..f3c4147
--- /dev/null
@@ -0,0 +1,120 @@
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 42511431FAF\r
+       for <notmuch@notmuchmail.org>; Sat, 22 Sep 2012 13:03:37 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id KHrDBtxqfPtx for <notmuch@notmuchmail.org>;\r
+       Sat, 22 Sep 2012 13:03:36 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 33198431FAE\r
+       for <notmuch@notmuchmail.org>; Sat, 22 Sep 2012 13:03:36 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+       by guru.guru-group.fi (Postfix) with ESMTP id 9E0E310014F;\r
+       Sat, 22 Sep 2012 23:03:40 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Austin Clements <amdragon@MIT.EDU>,\r
+       Justus Winter <4winter@informatik.uni-hamburg.de>\r
+Subject: Re: [PATCH 1/2] Annotate internal_error with the attribute noreturn\r
+In-Reply-To: <20120922161256.GE26662@mit.edu>\r
+References:\r
+ <1348231837-21700-1-git-send-email-4winter@informatik.uni-hamburg.de>\r
+       <20120922161256.GE26662@mit.edu>\r
+User-Agent: Notmuch/0.13.2+177~g6720ee8 (http://notmuchmail.org) Emacs/24.2.1\r
+       (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+       $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+       !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Sat, 22 Sep 2012 23:03:40 +0300\r
+Message-ID: <m2a9whlt9f.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 22 Sep 2012 20:03:37 -0000\r
+\r
+On Sat, Sep 22 2012, Austin Clements wrote:\r
+\r
+> LGTM, though I agree with David that this should return void now, if\r
+> that's possible.\r
+>\r
+> Do we want to wrap the __attribute__((noreturn)) in an #ifdef __GNUC__\r
+> (or provide a PRINTF_ATTRIBUTE-like macro) or is that already a lost\r
+> cause?\r
+\r
+Good point -- this should be NORETURN_ATTRIBUTE instead...\r
+\r
+Also, http://gcc.gnu.org/onlinedocs/gcc-4.3.2//gcc/Function-Attributes.html states:\r
+\r
+"It does not make sense for a noreturn function to have a return type other\r
+than void."\r
+\r
+(I think that hasn't changed since :)\r
+\r
+Tomi\r
+\r
+>\r
+> Quoth Justus Winter on Sep 21 at  2:50 pm:\r
+>> Annotating functions that do not return with the noreturn attribute\r
+>> (which is understood by both gcc and clang) prevents static analyzers\r
+>> from generating false positives (internal_error is used to terminate\r
+>> the process and is used extensively in error handling code paths).\r
+>> \r
+>> Remove the return statement that was placed there to appease the\r
+>> compiler. Functions annotated with noreturn are not supposed to return\r
+>> any values.\r
+>> \r
+>> Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>\r
+>> ---\r
+>>  util/error_util.c |    2 --\r
+>>  util/error_util.h |    2 +-\r
+>>  2 files changed, 1 insertion(+), 3 deletions(-)\r
+>> \r
+>> diff --git a/util/error_util.c b/util/error_util.c\r
+>> index 630d228..3cf353a 100644\r
+>> --- a/util/error_util.c\r
+>> +++ b/util/error_util.c\r
+>> @@ -35,7 +35,5 @@ _internal_error (const char *format, ...)\r
+>>      vfprintf (stderr, format, va_args);\r
+>>  \r
+>>      exit (1);\r
+>> -\r
+>> -    return 1;\r
+>>  }\r
+>>  \r
+>> diff --git a/util/error_util.h b/util/error_util.h\r
+>> index bb15822..24a644b 100644\r
+>> --- a/util/error_util.h\r
+>> +++ b/util/error_util.h\r
+>> @@ -30,7 +30,7 @@\r
+>>   * Note that PRINTF_ATTRIBUTE comes from talloc.h\r
+>>   */\r
+>>  int\r
+>> -_internal_error (const char *format, ...) PRINTF_ATTRIBUTE (1, 2);\r
+>> +_internal_error (const char *format, ...) PRINTF_ATTRIBUTE (1, 2) __attribute__ ((noreturn));\r
+>>  \r
+>>  /* There's no point in continuing when we've detected that we've done\r
+>>   * something wrong internally (as opposed to the user passing in a\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r