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

[PATCH v2 2/7] verify_signed_buffer: drop pbuf variable

From
Jeff King <peff@peff.net>
Date
Jun 17, 2016, 23:38 UTC
Message-ID
<20160617233839.GB31958@sigill.intra.peff.net>
In-Reply-To
<20160617233819.GA31909@sigill.intra.peff.net>

If our caller gave us a non-NULL gpg_status parameter, we write the gpg status into their strbuf. If they didn't, then we write it to a temporary local strbuf (since we still need to look at it). The variable "pbuf" adds an extra layer of indirection so that the rest of the function can just access whichever is appropriate.

However, the name "pbuf" isn't very descriptive, and it's easy to get confused about what is supposed to be in it (especially because we are reading both "status" and "output" from gpg).

Rather than give it a more descriptive name, we can just use gpg_status as our indirection pointer. Either it points to the caller's input, or we can point it directly to our temporary buffer.

Signed-off-by: Jeff King <peff@peff.net>
---
 gpg-interface.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/gpg-interface.c b/gpg-interface.c
index 0ed9fa7..216cad8 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -211,7 +211,6 @@ int verify_signed_buffer(const char *payload, size_t payload_size,
 	char path[PATH_MAX];
 	int fd, ret;
 	struct strbuf buf = STRBUF_INIT;
-	struct strbuf *pbuf = &buf;
 
 	fd = git_mkstemp(path, PATH_MAX, ".git_vtag_tmpXXXXXX");
 	if (fd < 0)
@@ -242,9 +241,9 @@ int verify_signed_buffer(const char *payload, size_t payload_size,
 		strbuf_read(gpg_output, gpg.err, 0);
 		close(gpg.err);
 	}
-	if (gpg_status)
-		pbuf = gpg_status;
-	strbuf_read(pbuf, gpg.out, 0);
+	if (!gpg_status)
+		gpg_status = &buf;
+	strbuf_read(gpg_status, gpg.out, 0);
 	close(gpg.out);
 
 	ret = finish_command(&gpg);
@@ -252,7 +251,7 @@ int verify_signed_buffer(const char *payload, size_t payload_size,
 
 	unlink_or_warn(path);
 
-	ret |= !strstr(pbuf->buf, "\n[GNUPG:] GOODSIG ");
+	ret |= !strstr(gpg_status->buf, "\n[GNUPG:] GOODSIG ");
 	strbuf_release(&buf); /* no matter it was used or not */
 
 	return ret;
-- 
2.9.0.165.g4aacdc3
Previous: Jeff KingNext: Jeff King
Message 17 of 22 in “gpg-interface cleanups”
  1. 0/7 gpg-interface cleanupsJeff King, Jun 16, 2016
  2. 1/7 gpg-interface: use child_process.argsJeff King, Jun 16, 2016
  3. 2/7 verify_signed_buffer: drop pbuf variableJeff King, Jun 16, 2016
  4. 3/7 verify_signed_buffer: use tempfile objectJeff King, Jun 16, 2016
  5. 4/7 run-command: add pipe_command helperJeff King, Jun 16, 2016
  6. Eric SunshineJun 17, 2016
  7. Jeff KingJun 17, 2016
  8. Eric SunshineJun 17, 2016
  9. 5/7 verify_signed_buffer: use pipe_commandJeff King, Jun 16, 2016
  10. 6/7 sign_buffer: use pipe_commandJeff King, Jun 16, 2016
  11. 7/7 gpg-interface: check gpg signature creation statusJeff King, Jun 16, 2016
  12. Junio C HamanoJun 16, 2016
  13. Michael J GruberJun 17, 2016
  14. Jeff KingJun 17, 2016
  15. 0/7 gpg-interface cleanupsJeff King, Jun 17, 2016
  16. 1/7 gpg-interface: use child_process.argsJeff King, Jun 17, 2016
  17. 2/7 verify_signed_buffer: drop pbuf variableJeff King, Jun 17, 2016
  18. 3/7 verify_signed_buffer: use tempfile objectJeff King, Jun 17, 2016
  19. 4/7 run-command: add pipe_command helperJeff King, Jun 17, 2016
  20. 5/7 verify_signed_buffer: use pipe_commandJeff King, Jun 17, 2016
  21. 6/7 sign_buffer: use pipe_commandJeff King, Jun 17, 2016
  22. 7/7 gpg-interface: check gpg signature creation statusJeff King, Jun 17, 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.