Thread (1 message) 1 message, 1 author, 2025-11-10

Re: [PATCH 07/12] diff: update the way rewrite diff handles incomplete lines

From: Junio C Hamano <hidden>
Date: 2025-11-10 18:33:17

Phillip Wood [off-list ref] writes:
quoted
  		endp = memchr(data, '\n', size);
  		len = endp ? (endp - data + 1) : size;
+		plen = len;
+
+		if (!endp) {
+			plen = len + 1;
+			pdata = xmalloc(plen + 2);
+			memcpy(pdata, data, len);
+			pdata[len] = '\n';
+			pdata[len + 1] = '\0';
+		}
I think it would be clearer to refactor this as

  		endp = memchr(data, '\n', size);
-		len = endp ? (endp - data + 1) : size;
		if (endp) {
			len = endp - data + 1;
			plen = len;
		} else {
			len = size;
+			plen = len + 1;
+			pdata = xmalloc(plen + 2);
+			memcpy(pdata, data, len);
+			pdata[len] = '\n';
+			pdata[len + 1] = '\0';
+		}
Perhaps.  I'll try and see if I agree.

Thanks.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help