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

Re: [PATCH 2/2] blame: simplify prepare_lines()

From
René Scharfe <l.s.r@web.de>
Date
Jun 13, 2014, 21:33 UTC
Message-ID
<539B6E31.1080901@web.de>
In-Reply-To
<20140613211339.GL8557@google.com>
Am 13.06.2014 23:13, schrieb Jonathan Nieder:
Show 12 quoted lines
> René Scharfe wrote:
>
>> -	if (incomplete)
>> -		*lineno++ = len;
>> +	*lineno = len;
>>
>> -	sb->num_lines = num + incomplete;
>> +	sb->num_lines = num;
>
> This will always treat whatever comes after the last newline as an
> incomplete line, even if it has zero length.  Is that safe?  (Not a
> rhetorical question --- I haven't looked carefully at the caller.)

There is no need to look at the caller -- the contents of the lineno array is not (intended to be) changed by the patch.

The original code is:
	p = memchr(p, '\n', end - p);
	if (p) {
		p++;
		*lineno++ = p - buf;
		continue;
	}

Suppose there is no incomplete line. For the last EOL of a buffer, p points to buf[len - 1] after the memchr call. Then it is incremented. Then buf + len - buf is written into the last lineno member -- same as after the patch.

Makes sense?
René
Previous: Jonathan NiederNext: Jonathan Nieder
Message 4 of 6 in “blame: factor out get_next_line()”
  1. 1/2 blame: factor out get_next_line()René Scharfe, Jun 13, 2014
  2. 2/2 blame: simplify prepare_lines()René Scharfe, Jun 13, 2014
  3. Jonathan NiederJun 13, 2014
  4. René ScharfeJun 13, 2014
  5. Jonathan NiederJun 13, 2014
  6. Jonathan NiederJun 13, 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.