All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Han-Wen Nienhuys <hanwen@google.com>,
	Karthik Nayak <karthik.188@gmail.com>
Subject: Re: [PATCH v4 1/2] refs: introduce reftable backend
Date: Thu, 8 Feb 2024 06:11:57 +0100	[thread overview]
Message-ID: <ZcRinffkQJNWyiGZ@tanuki> (raw)
In-Reply-To: <20240207223120.GA537741@coredump.intra.peff.net>

[-- Attachment #1: Type: text/plain, Size: 2495 bytes --]

On Wed, Feb 07, 2024 at 05:31:20PM -0500, Jeff King wrote:
> On Wed, Feb 07, 2024 at 08:20:31AM +0100, Patrick Steinhardt wrote:
> 
> > +static int write_copy_table(struct reftable_writer *writer, void *cb_data)
> > +{
> > [...]
> > +	/*
> > +	 * Create the reflog entry for the newly created branch.
> > +	 */
> > +	ALLOC_GROW(logs, logs_nr + 1, logs_alloc);
> > +	memset(&logs[logs_nr], 0, sizeof(logs[logs_nr]));
> > +	fill_reftable_log_record(&logs[logs_nr]);
> > +	logs[logs_nr].refname = (char *)arg->newname;
> > +	logs[logs_nr].update_index = creation_ts;
> > +	logs[logs_nr].value.update.message =
> > +		xstrndup(arg->logmsg, arg->refs->write_options.block_size / 2);
> > +	logs[logs_nr].value.update.new_hash = old_ref.value.val1;
> > +	logs_nr++;
> > +
> > +	/*
> > +	 * In addition to writing the reflog entry for the new branch, we also
> > +	 * copy over all log entries from the old reflog. Last but not least,
> > +	 * when renaming we also have to delete all the old reflog entries.
> > +	 */
> > +	ret = reftable_merged_table_seek_log(mt, &it, arg->oldname);
> > +	if (ret < 0)
> > +		return ret;
> 
> Should this last line be "goto done" as is used elsewhere in the
> function? Otherwise we are at least leaking the "logs" array (and
> possibly some of the other cleanup is important, too).

Indeed we should.

> > +	while (1) {
> > +		ret = reftable_iterator_next_log(&it, &old_log);
> > +		if (ret < 0)
> > +			goto done;
> > +		if (ret > 0 || strcmp(old_log.refname, arg->oldname)) {
> > +			ret = 0;
> > +			break;
> > +		}
> 
> This "ret = 0" doesn't have any effect. We break out of the loop, and
> then...
> 
> > +	}
> > +
> > +	ret = reftable_writer_add_logs(writer, logs, logs_nr);
> > +	if (ret < 0)
> > +		goto done;
> 
> ...the first thing we do is write over it. I dunno if it's worth keeping
> as a maintenance precaution, though (if the code after the loop changed
> to omit that assignment, then setting "ret" would become important).

Yeah, I think this one we should keep. It's also a repeating pattern
that we have in many other places, so it helps lower the mental burden
when it looks similar to all the others.

> Both were noticed by Coverity (along with several other false
> positives).

Is the Coverity instance publicly accessible? If not, can you maybe
invite me so that I get a better feeling for them?

I'll send a patch to fix the missing `goto done` above, thanks!

Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2024-02-08  5:12 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30  8:05 [PATCH 0/2] refs: introduce reftable backend Patrick Steinhardt
2024-01-30  8:05 ` [PATCH 1/2] " Patrick Steinhardt
2024-02-01 15:17   ` Karthik Nayak
2024-02-02  8:30     ` Patrick Steinhardt
2024-02-02 10:52       ` Patrick Steinhardt
2024-01-30  8:05 ` [PATCH 2/2] ci: add jobs to test with the " Patrick Steinhardt
2024-01-30 22:08 ` [PATCH 0/2] refs: introduce " Junio C Hamano
2024-02-02  8:38 ` [PATCH v2 " Patrick Steinhardt
2024-02-02  8:38   ` [PATCH v2 1/2] " Patrick Steinhardt
2024-02-02  8:38   ` [PATCH v2 2/2] ci: add jobs to test with the " Patrick Steinhardt
2024-02-02 13:02   ` [PATCH v2 0/2] refs: introduce " Karthik Nayak
2024-02-03 20:41   ` Junio C Hamano
2024-02-04  6:00     ` Patrick Steinhardt
2024-02-05  6:02 ` [PATCH v3 " Patrick Steinhardt
2024-02-05  6:02   ` [PATCH v3 1/2] " Patrick Steinhardt
2024-02-05  6:02   ` [PATCH v3 2/2] ci: add jobs to test with the " Patrick Steinhardt
2024-02-05 13:10   ` [PATCH v3 0/2] refs: introduce " Karthik Nayak
2024-02-07  7:20 ` [PATCH v4 " Patrick Steinhardt
2024-02-07  7:20   ` [PATCH v4 1/2] " Patrick Steinhardt
2024-02-07 22:31     ` Jeff King
2024-02-08  5:11       ` Patrick Steinhardt [this message]
2024-02-15  5:39         ` Jeff King
2024-02-07  7:20   ` [PATCH v4 2/2] ci: add jobs to test with the " Patrick Steinhardt

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=ZcRinffkQJNWyiGZ@tanuki \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=hanwen@google.com \
    --cc=karthik.188@gmail.com \
    --cc=peff@peff.net \
    /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.