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

Re: [PATCH] config: avoid "write_in_full(fd, buf, len) != len" pattern

From
PWPhillip Wood <phillip.wood@talktalk.net>
Date
Nov 18, 2017, 11:27 UTC
Message-ID
<6f1cf9ac-42e4-76b2-6936-4646a5cb574c@talktalk.net>
In-Reply-To
<20171117220633.6yoovfgpbr3rsykr@sigill.intra.peff.net>
On 17/11/17 22:06, Jeff King wrote:
Show 16 quoted lines
> On Wed, Nov 15, 2017 at 12:40:43PM +0000, Phillip Wood wrote:
> 
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> As explained in commit 06f46f237 (avoid "write_in_full(fd, buf, len)
>> != len" pattern, 2017–09–13) the return value of write_in_full() is
>> either -1 or the requested number of bytes. As such comparing the
>> return value to an unsigned value such as strbuf.len will fail to
>> catch errors. Change the code to use the preferred '< 0' check.
> 
> Thanks for catching this. I wondered at first how I missed these obvious
> cases, but the answer is that they were added after my commit. :)
> 
> There's one more case in write_section() that uses "==". That's not
> actually wrong, but I wonder if we'd want to make it "< 0" for
> consistency.

Yes, I noticed that but didn't get round to looking at it properly the other day. Rene's fix looks good to me.

Best Wishes
Phillip
Previous: René Scharfe
Message 7 of 7 in “config: avoid "write_in_full(fd, buf, len) != len" pattern”
  1. config: avoid "write_in_full(fd, buf, len) != len" patternPhillip Wood, Nov 15, 2017
  2. Junio C HamanoNov 16, 2017
  3. Jeff KingNov 17, 2017
  4. René ScharfeNov 18, 2017
  5. Jeff KingNov 18, 2017
  6. René ScharfeNov 18, 2017
  7. Phillip WoodNov 18, 2017

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.