git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] remote-http: use argv-array

From
Jeff King <peff@peff.net>
Date
Jul 9, 2013, 06:38 UTC
Message-ID
<20130709063840.GA8015@sigill.intra.peff.net>
In-Reply-To
<CAKPyHN0DG0c2vxWtybYtDmFKMo369PZcbqCfDJaXeiRV+PP8pQ@mail.gmail.com>
On Tue, Jul 09, 2013 at 08:05:19AM +0200, Bert Wesarg wrote:
Show 7 quoted lines
> > +       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
Previous: Bert WesargNext: Matt Kraai
Message 3 of 17 in “remote-http: use argv-array”
  1. remote-http: use argv-arrayJunio C Hamano, Jul 9, 2013
  2. Bert WesargJul 9, 2013
  3. Jeff KingJul 9, 2013
  4. Matt KraaiJul 9, 2013
  5. Jeff KingJul 10, 2013
  6. 1/3 add missing "format" function attributesJeff King, Jul 10, 2013
  7. 2/3 use "sentinel" function attribute for variadic listsJeff King, Jul 10, 2013
  8. 3/3 wt-status: use "format" function attribute for status_printfJeff King, Jul 10, 2013
  9. Junio C HamanoJul 10, 2013
  10. Jeff KingJul 10, 2013
  11. Junio C HamanoJul 10, 2013
  12. Jeff KingJul 10, 2013
  13. Junio C HamanoJul 10, 2013
  14. Jeff KingJul 10, 2013
  15. Junio C HamanoJul 10, 2013
  16. Junio C HamanoJul 12, 2013
  17. Jeff KingJul 12, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.