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

Re: [PATCH 2/2] read-cache: fix an -Wmaybe-uninitialized warning

From
Ramsay Jones <ramsay@ramsayjones.plus.com>
Date
Mar 20, 2018, 22:52 UTC
Message-ID
<e3894650-3639-c871-1291-f3efa7fbea0a@ramsayjones.plus.com>
In-Reply-To
<20180320043652.GC13302@sigill.intra.peff.net>
On 20/03/18 04:36, Jeff King wrote:
> On Mon, Mar 19, 2018 at 05:56:11PM +0000, Ramsay Jones wrote:
> 
[snip]
Show 25 quoted lines
>> diff --git a/read-cache.c b/read-cache.c
>> index 2eb81a66b..49607ddcd 100644
>> --- a/read-cache.c
>> +++ b/read-cache.c
>> @@ -2104,13 +2104,15 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce,
>>  			  struct strbuf *previous_name, struct ondisk_cache_entry *ondisk)
>>  {
>>  	int size;
>> -	int saved_namelen = saved_namelen; /* compiler workaround */
>>  	int result;
>> +	unsigned int saved_namelen;
>> +	int stripped_name = 0;
> 
> Maybe too clever, but I think you could just do:
> 
>   unsigned int saved_namelen = 0;
>   ...
> 	saved_namelen = ce_namelen(ce);
>   ...
>   if (saved_namelen)
> 	ce->ce_namelen = saved_namelen;
>   ce->ce_flags &= ~CE_STRIP_NAME;
> 
> the zero-length name case (if that's even legal) would work out the
> same.

Yeah, that was one option that I looked at. The first option was to initialise saved_namelen to -1 (it was still an int) then the test became if (saved_namelen >= 0). However, that started me thinking about the zero-length case - should I assert if ((ce->ce_flags & CE_STRIP_NAME) && (ce_namelen(ce) == 0))? etc.

In the end, I decided that I wanted it to be 'drop dead' obvious what was going on! Hopefully, the result was just that. :-D

ATB, Ramsay Jones

Previous: Jeff KingNext: Jeff King
Message 3 of 4 in “read-cache: fix an -Wmaybe-uninitialized warning”
  1. 2/2 read-cache: fix an -Wmaybe-uninitialized warningRamsay Jones, Mar 19, 2018
  2. Jeff KingMar 20, 2018
  3. Ramsay JonesMar 20, 2018
  4. Jeff KingMar 21, 2018

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.