From: Junio C Hamano <gitster@pobox.com>
To: rappazzo@gmail.com
Cc: git@vger.kernel.org, "Torsten Bögershausen" <tboegi@web.de>
Subject: Re: What's cooking in git.git (Oct 2015, #01; Mon, 5)
Date: Mon, 05 Oct 2015 22:55:49 -0700 [thread overview]
Message-ID: <xmqqd1wswnfe.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <561339C1.704@web.de> ("Torsten Bögershausen"'s message of "Tue, 6 Oct 2015 05:02:25 +0200")
Torsten Bögershausen <tboegi@web.de> writes:
> Minor comment from my compiler:
>
> worktree.c:181: warning: assuming signed overflow does not occur when assuming
> that (X + c) > X is always true
Thanks; I think the allocation in that function (the use it uses
ALLOC_GROW()) is somewhat bogus.
It does this:
if ((linked = get_linked_worktree(d->d_name))) {
ALLOC_GROW(list, alloc + 1, alloc);
list[counter++] = linked;
}
where "alloc" keeps track of the size of the list, and "counter"
keeps track of the first unused entry. The second argument to the
helper macro smells bad.
The correct way to use ALLOC_GROW() helper macro is:
* Use three variables, an array, the size of the allocation and the
size of the used part of the array. If you call the array $thing,
the size of the allocation is typically called $thing_alloc and
the size of the used part $thing_nr. E.g. opts[], opts_alloc & opts_nr.
* When adding a new thing at the end of the $thing, do this:
ALLOC_GROW($thing, $thing_nr + 1, $thing_alloc);
$thing[$thing_nr++] = <<new thing>>;
Perhaps something like this needs squashing in.
Subject: [PATCH] fixup! worktree: add a function to get worktree details
---
worktree.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/worktree.c b/worktree.c
index 90282d9..f7304a2 100644
--- a/worktree.c
+++ b/worktree.c
@@ -178,12 +178,13 @@ struct worktree **get_worktrees(void)
continue;
if ((linked = get_linked_worktree(d->d_name))) {
- ALLOC_GROW(list, alloc + 1, alloc);
+ ALLOC_GROW(list, counter + 1, alloc);
list[counter++] = linked;
}
}
closedir(dir);
}
+ ALLOC_GROW(list, counter + 1, alloc);
list[counter] = NULL;
return list;
}
--
2.6.1-284-g1f14bb6
next prev parent reply other threads:[~2015-10-06 5:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-05 22:59 What's cooking in git.git (Oct 2015, #01; Mon, 5) Junio C Hamano
2015-10-06 3:02 ` Torsten Bögershausen
2015-10-06 5:55 ` Junio C Hamano [this message]
2015-10-06 19:30 ` Mike Rappazzo
2015-10-06 4:45 ` Torsten Bögershausen
2015-10-06 5:35 ` Junio C Hamano
2015-10-06 6:32 ` Matthieu Moy
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=xmqqd1wswnfe.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=rappazzo@gmail.com \
--cc=tboegi@web.de \
/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.