git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Bert Wesarg <bert.wesarg@googlemail.com>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH] remote-http: use argv-array
Date: Tue, 9 Jul 2013 02:38:40 -0400	[thread overview]
Message-ID: <20130709063840.GA8015@sigill.intra.peff.net> (raw)
In-Reply-To: <CAKPyHN0DG0c2vxWtybYtDmFKMo369PZcbqCfDJaXeiRV+PP8pQ@mail.gmail.com>

On Tue, Jul 09, 2013 at 08:05:19AM +0200, Bert Wesarg wrote:

> > +       argv_array_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status");
> 
> missing NULL sentinel. GCC has the 'sentinel' [1] attribute to catch
> such errors. Or use macro magic:
> 
> void argv_array_pushl_(struct argv_array *array, ...);
> #define argv_array_pushl(array, ...) argv_array_pushl_(array, __VA_ARGS__, NULL)

Nice catch. We cannot use variadic macros, because we support pre-C99
compilers that do not have them. But the sentinel attribute is a good
idea. Here's a patch.

-- >8 --
Subject: [PATCH] argv-array: add sentinel attribute to argv_array_pushl

This attribute can help gcc notice when callers forget to add a
NULL sentinel to the end of the function. We shouldn't need
to #ifdef for other compilers, as __attribute__ is already a
no-op on non-gcc-compatible compilers.

Suggested-by: Bert Wesarg <bert.wesarg@googlemail.com>
Signed-off-by: Jeff King <peff@peff.net>
---
This is our first use of an __attribute__ that is not "noreturn" or
"format". I assume this one should be supported on other gcc-compatible
compilers like clang.

 argv-array.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/argv-array.h b/argv-array.h
index 40248d4..e805748 100644
--- a/argv-array.h
+++ b/argv-array.h
@@ -15,6 +15,7 @@ void argv_array_pushf(struct argv_array *, const char *fmt, ...);
 void argv_array_push(struct argv_array *, const char *);
 __attribute__((format (printf,2,3)))
 void argv_array_pushf(struct argv_array *, const char *fmt, ...);
+__attribute__((sentinel))
 void argv_array_pushl(struct argv_array *, ...);
 void argv_array_pop(struct argv_array *);
 void argv_array_clear(struct argv_array *);
-- 
1.8.3.rc3.24.gec82cb9

  reply	other threads:[~2013-07-09  6:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-09  5:18 Junio C Hamano
2013-07-09  6:05 ` Bert Wesarg
2013-07-09  6:38   ` Jeff King [this message]
2013-07-09 22:27     ` Matt Kraai
2013-07-10  0:16       ` Jeff King
2013-07-10  0:18         ` [PATCH 1/3] add missing "format" function attributes Jeff King
2013-07-10  0:19         ` [PATCH 2/3] use "sentinel" function attribute for variadic lists Jeff King
2013-07-10  0:23         ` [PATCH 3/3] wt-status: use "format" function attribute for status_printf Jeff King
2013-07-10  5:26           ` Junio C Hamano
2013-07-10  5:28             ` Jeff King
2013-07-10  5:35               ` Junio C Hamano
2013-07-10  5:40                 ` Jeff King
2013-07-10  5:52                   ` Junio C Hamano
2013-07-10  6:11                     ` Jeff King
2013-07-10  6:17                       ` Junio C Hamano
2013-07-12 16:10               ` Junio C Hamano
2013-07-12 20:44                 ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130709063840.GA8015@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=bert.wesarg@googlemail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --subject='Re: [PATCH] remote-http: use argv-array' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).