From: Junio C Hamano <gitster@pobox•com>
To: Stefan Beller <stefanbeller@gmail•com>
Cc: pdebie@ai•rug.nl, git@vger•kernel.org
Subject: Re: [PATCH] help: Fix size passed to qsort
Date: Thu, 18 Sep 2014 10:34:48 -0700 [thread overview]
Message-ID: <xmqqzjdwomrr.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <xmqq8ulgq25h.fsf@gitster.dls.corp.google.com> (Junio C. Hamano's message of "Thu, 18 Sep 2014 10:17:14 -0700")
Junio C Hamano <gitster@pobox•com> writes:
> Stefan Beller <stefanbeller@gmail•com> writes:
>
>> We actually want to have the size of one 'name' and not the size
>> of the names array.
> ...
> I suspect that the latter is "size of a pointer that points at a
> cmdname structure", but the original code in help_unknown_cmd() is
> wrong. The ones in load_command_list() do this correctly and
> another qsort() invocation in this function does so as well. I
> wonder why they didn't correctly cut&paste ;-)
>
> 746c221a (git wrapper: also use aliases to correct mistyped
> commands, 2008-09-10) seemed to have introduced the culprit.
>
> The call to uniq() would fail to uniquify because main_cmds would
> have the standard command all in front and then aliases and commands
> in the user's PATH later, but I do not quite see if there is any
> end-user observable breakages that can arise from this. What is the
> practical implication of this breakage?
Heh, I should have spent a bit more time before starting to type.
The answer probably is "nothing", as
struct cmdnames {
...
struct cmdname {
...
} **names;
} main_cmds;
is what we are dealing here, so main_cmds.names is a pointer that
points at a slab of memory to hold many pointers, each of which
points at "struct cmdname". And sizeof(struct cmdname **) is
incorrectly passed where we should pass sizeof(struct cmdname *),
which you fixed, but in practice they would be the same size anyway
;-)
>> qsort(main_cmds.names, main_cmds.cnt,
>> - sizeof(main_cmds.names), cmdname_compare);
>> + sizeof(*main_cmds.names), cmdname_compare);
>> uniq(&main_cmds);
>>
>> /* This abuses cmdname->len for levenshtein distance */
prev parent reply other threads:[~2014-09-18 17:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-17 12:14 [PATCH] help: Fix size passed to qsort Stefan Beller
2014-09-18 17:17 ` Junio C Hamano
2014-09-18 17:34 ` Junio C Hamano [this message]
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=xmqqzjdwomrr.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=pdebie@ai$(echo .)rug.nl \
--cc=stefanbeller@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox