All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: Michael J Gruber <git@drmicha.warpmail.net>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 2/7] verify_signed_buffer: drop pbuf variable
Date: Thu, 16 Jun 2016 05:34:07 -0400	[thread overview]
Message-ID: <20160616093406.GB15851@sigill.intra.peff.net> (raw)
In-Reply-To: <20160616093248.GA15130@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.160.g4984cba


  parent reply	other threads:[~2016-06-16  9:34 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-16  9:32 [PATCH 0/7] gpg-interface cleanups Jeff King
2016-06-16  9:33 ` [PATCH 1/7] gpg-interface: use child_process.args Jeff King
2016-06-16  9:34 ` Jeff King [this message]
2016-06-16  9:35 ` [PATCH 3/7] verify_signed_buffer: use tempfile object Jeff King
2016-06-16  9:37 ` [PATCH 4/7] run-command: add pipe_command helper Jeff King
2016-06-17 20:03   ` Eric Sunshine
2016-06-17 23:28     ` Jeff King
2016-06-17 23:31       ` Eric Sunshine
2016-06-16  9:38 ` [PATCH 5/7] verify_signed_buffer: use pipe_command Jeff King
2016-06-16  9:39 ` [PATCH 6/7] sign_buffer: " Jeff King
2016-06-16  9:42 ` [PATCH 7/7] gpg-interface: check gpg signature creation status Jeff King
2016-06-16 18:20 ` [PATCH 0/7] gpg-interface cleanups Junio C Hamano
2016-06-17  9:20   ` Michael J Gruber
2016-06-17  9:21     ` Jeff King
2016-06-17 23:38 ` [PATCH v2 " Jeff King
2016-06-17 23:38   ` [PATCH v2 1/7] gpg-interface: use child_process.args Jeff King
2016-06-17 23:38   ` [PATCH v2 2/7] verify_signed_buffer: drop pbuf variable Jeff King
2016-06-17 23:38   ` [PATCH v2 3/7] verify_signed_buffer: use tempfile object Jeff King
2016-06-17 23:38   ` [PATCH v2 4/7] run-command: add pipe_command helper Jeff King
2016-06-17 23:38   ` [PATCH v2 5/7] verify_signed_buffer: use pipe_command Jeff King
2016-06-17 23:38   ` [PATCH v2 6/7] sign_buffer: " Jeff King
2016-06-17 23:38   ` [PATCH v2 7/7] gpg-interface: check gpg signature creation status 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

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

  git send-email \
    --in-reply-to=20160616093406.GB15851@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@drmicha.warpmail.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.