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

[PATCH v4 1/8] trailer: improve const correctness

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Oct 20, 2016, 21:39 UTC
Message-ID
<701ba7164b587a97ef380bc981c95c5d51db6781.1476998988.git.jonathantanmy@google.com>
In-Reply-To
<cover.1476998988.git.jonathantanmy@google.com>

Change "const char *" to "char *" in struct trailer_item and in the return value of apply_command (since those strings are owned strings).

Change "struct conf_info *" to "const struct conf_info *" (since that struct is not modified).

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
 trailer.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/trailer.c b/trailer.c
index c6ea9ac..1f191b2 100644
--- a/trailer.c
+++ b/trailer.c
@@ -27,8 +27,8 @@ static struct conf_info default_conf_info;
 struct trailer_item {
 	struct trailer_item *previous;
 	struct trailer_item *next;
-	const char *token;
-	const char *value;
+	char *token;
+	char *value;
 	struct conf_info conf;
 };
 
@@ -95,8 +95,8 @@ static void free_trailer_item(struct trailer_item *item)
 	free(item->conf.name);
 	free(item->conf.key);
 	free(item->conf.command);
-	free((char *)item->token);
-	free((char *)item->value);
+	free(item->token);
+	free(item->value);
 	free(item);
 }
 
@@ -215,13 +215,13 @@ static struct trailer_item *remove_first(struct trailer_item **first)
 	return item;
 }
 
-static const char *apply_command(const char *command, const char *arg)
+static char *apply_command(const char *command, const char *arg)
 {
 	struct strbuf cmd = STRBUF_INIT;
 	struct strbuf buf = STRBUF_INIT;
 	struct child_process cp = CHILD_PROCESS_INIT;
 	const char *argv[] = {NULL, NULL};
-	const char *result;
+	char *result;
 
 	strbuf_addstr(&cmd, command);
 	if (arg)
@@ -425,7 +425,7 @@ static int set_if_missing(struct conf_info *item, const char *value)
 	return 0;
 }
 
-static void duplicate_conf(struct conf_info *dst, struct conf_info *src)
+static void duplicate_conf(struct conf_info *dst, const struct conf_info *src)
 {
 	*dst = *src;
 	if (src->name)
-- 
2.8.0.rc3.226.g39d4020
Previous: Jonathan TanNext: Jonathan Tan
Message 2 of 19 in “allow non-trailers and multiple-line trailers”
  1. 0/8 allow non-trailers and multiple-line trailersJonathan Tan, Oct 20, 2016
  2. 1/8 trailer: improve const correctnessJonathan Tan, Oct 20, 2016
  3. 2/8 trailer: use list.h for doubly-linked listJonathan Tan, Oct 20, 2016
  4. 6/8 trailer: allow non-trailers in trailer blockJonathan Tan, Oct 20, 2016
  5. 5/8 trailer: clarify failure modes in parse_trailerJonathan Tan, Oct 20, 2016
  6. Stefan BellerOct 20, 2016
  7. Junio C HamanoOct 20, 2016
  8. Jonathan TanOct 20, 2016
  9. Junio C HamanoOct 20, 2016
  10. Jonathan TanOct 20, 2016
  11. Junio C HamanoOct 21, 2016
  12. Christian CouderOct 22, 2016
  13. Junio C HamanoOct 22, 2016
  14. Christian CouderOct 22, 2016
  15. Jonathan TanOct 20, 2016
  16. 8/8 trailer: support values folded to multiple linesJonathan Tan, Oct 20, 2016
  17. 4/8 trailer: make args have their own structJonathan Tan, Oct 20, 2016
  18. 7/8 trailer: forbid leading whitespace in trailersJonathan Tan, Oct 20, 2016
  19. 3/8 trailer: streamline trailer item create and addJonathan Tan, Oct 20, 2016

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.