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

[PATCH 1/2] git-compat-util.h: drop trailing semicolon from macro definition

From
René Scharfe. <l.s.r@web.de>
Date
Mar 13, 2021, 16:10 UTC
Message-ID
<b417c7cc-8e40-04df-0314-d4c3fab278b7@web.de>

Make CALLOC_ARRAY usable like a function by requiring callers to supply the trailing semicolon, which all of the current ones already do. With the extra semicolon e.g. the following code wouldn't compile because it disconnects the "else" from the "if":

	if (condition)
		CALLOC_ARRAY(ptr, n);
	else
		whatever();
Signed-off-by: René Scharfe <l.s.r@web.de>
---
 git-compat-util.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index 3b2738c73d..dcc786edaa 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -898,7 +898,7 @@ int xstrncmpz(const char *s, const char *t, size_t len);
 #define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)

 #define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))
-#define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)));
+#define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))
 #define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))

 #define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \
--
2.30.2
Next: René Scharfe.
Message 1 of 5 in “git-compat-util.h: drop trailing semicolon from macro definition”
  1. 1/2 git-compat-util.h: drop trailing semicolon from macro definitionRené Scharfe., Mar 13, 2021
  2. 2/2 use CALLOC_ARRAYRené Scharfe., Mar 13, 2021
  3. René Scharfe.Mar 15, 2021
  4. xcalloc: use CALLOC_ARRAY() when applicableJunio C Hamano, Mar 16, 2021
  5. Derrick StoleeMar 16, 2021

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.