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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 13.06.2014 23:13, schrieb Jonathan Nieder:
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é
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]