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

Re: [PATCH] Initialise hash variable to prevent compiler warnings

From
Felipe Franciosi <felipe@paradoxo.org>
Date
Oct 13, 2014, 21:55 UTC
Message-ID
<CANxchRRtd03LvjbWO7d45EE-GB_yTZjEhcJccZW_Y3mgDpENrQ@mail.gmail.com>
In-Reply-To
<CANxchRS1mGapb77hc9Ywqj_-8UeexSAWK4UK9y9M76pvoN-Yeg@mail.gmail.com>
On Mon, Oct 13, 2014 at 10:53 PM, Felipe Franciosi <felipe@paradoxo.org> wrote:
Show 14 quoted lines
>
> On Mon, Oct 13, 2014 at 9:12 PM, Junio C Hamano <gitster@pobox.com> wrote:
>>
>> Felipe Franciosi <felipe@paradoxo.org> writes:
>>
>> > The 'hash' variable in test-hashmap.c is not initialised properly
>> > which causes some 'gcc' versions to complain during compilation.
>>
>> FNV/I/IDIV10/0 covers all the possibilities of (method & 3), I would
>> have to say that the compiler needs to be fixed.
>>
>> Or insert "default:" just before "case HASH_METHOD_0:" line?
>>
>> I dunno.

Hmm... The "default:" would work, but is it really that bad to initialise a local variable in this case?

In any case, the compilation warning is annoying. Do you prefer the default or the initialisation?

Cheers, F.

Show 35 quoted lines
>
>
> Hmm... The "default:" would work, but is it really that bad to initialise a
> local variable in this case?
>
> In any case, the compilation warning is annoying. Do you prefer the default
> or the initialisation?
>
> Cheers,
> F.
>
>>
>> >
>> > Signed-off-by: Felipe Franciosi <felipe@paradoxo.org>
>> > ---
>> >  test-hashmap.c |    2 +-
>> >  1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> > diff --git a/test-hashmap.c b/test-hashmap.c
>> > index 07aa7ec..cc2891d 100644
>> > --- a/test-hashmap.c
>> > +++ b/test-hashmap.c
>> > @@ -47,7 +47,7 @@ static struct test_entry *alloc_test_entry(int hash,
>> > char *key, int klen,
>> >
>> >  static unsigned int hash(unsigned int method, unsigned int i, const
>> > char *key)
>> >  {
>> > -     unsigned int hash;
>> > +     unsigned int hash = 0;
>> >       switch (method & 3)
>> >       {
>> >       case HASH_METHOD_FNV:
>
>
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 6 in “Initialise hash variable to prevent compiler warnings”
  1. Initialise hash variable to prevent compiler warningsFelipe Franciosi, Oct 13, 2014
  2. Junio C HamanoOct 13, 2014
  3. Felipe FranciosiOct 13, 2014
  4. Junio C HamanoOct 14, 2014
  5. Felipe FranciosiOct 14, 2014
  6. Junio C HamanoOct 14, 2014

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.