🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #3520

[PATCH 1/2] combine-diff: fix the shift for the 33rd parent and later

#3520
From: Aniket Gupta
Date: Sat, 21 Nov 2026 10:42
73 lines
13162 bytes
coalesce_lines() records which parents lost a line by setting a bit in
the parent_map of that line. The bit is computed with 1<<parent, which
is an int shift. For the 33rd parent and later the shift count is 32 or
more, so the result is undefined, and in practice the bit for parent
minus 32 is set instead. The line is then shown in the wrong column of
the combined diff, and the hunk header can disagree with the lines in
the hunk.

Use 1UL<<parent, like the other masks in this file. parent_map is an
unsigned long.

Add a test where two of forty parents lose the same line. It is skipped
where long is not 64 bits, as the masks cannot hold that many parents
there.

Reported-by: Sami Jawhar <sami@theorem.dev>
Signed-off-by: Aniket Gupta <aniketgupta3001@gmail.com>
---
 combine-diff.c           |  2 +-
 t/t4038-diff-combined.sh | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/combine-diff.c b/combine-diff.c
index 717d537688..54d0aed6b2 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -246,7 +246,7 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
 	j--;
 	while (i != 0 || j != 0) {
 		if (directions[i][j] == MATCH) {
-			baseend->parent_map |= 1<<parent;
+			baseend->parent_map |= 1UL << parent;
 			baseend = baseend->prev;
 			newend = newend->prev;
 			i--;
diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh
index e11b711388..fcf7333d7b 100755
--- a/t/t4038-diff-combined.sh
+++ b/t/t4038-diff-combined.sh
@@ -127,6 +127,30 @@ test_expect_success 'check --cc --raw with forty trees' '
 	test_grep "^::::::::::::::::::::::::::::::::::::::::[^:]" out
 '
 
+test_expect_success LONG_IS_64BIT 'check --cc with forty parents, two losing the same line' '
+	blob=$(echo file | git hash-object --stdin -w) &&
+	result_tree=$(echo "100644 blob $blob	file" | git mktree) &&
+	parent_trees= &&
+	for i in $(test_seq 1 40)
+	do
+		case $i in
+		2 | 40)
+			extra=common
+			;;
+		*)
+			extra=
+			;;
+		esac &&
+		blob=$(test_write_lines $extra file file$i | git hash-object --stdin -w) &&
+		parent_trees="$parent_trees$(echo "100644 blob $blob	file" | git mktree)$LF" || return 1
+	done &&
+	git diff --cc $result_tree $parent_trees >out &&
+	# Check that the second and the fortieth column mark the line:
+	printf " -%37s-common\n" "" >expect &&
+	grep common out >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'setup combined ignore spaces' '
 	git checkout main &&
 	>test &&
-- 
2.54.0 (Apple Git-157)
Technical Details
Message-ID: <20261121104234.98386-2-aniketgupta3001@gmail.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76013-linux-kernel-git=dewy.ru
References: <20261121104234.98386-1-aniketgupta3001@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76013-linux-kernel-git=dewy.ru
From: aniketgupta3001@gmail.com (Aniket Gupta)
Newsgroups: linux.kernel.git
Subject: [PATCH 1/2] combine-diff: fix the shift for the 33rd parent and later
Date: Sat, 21 Nov 2026 16:12:33 +0530
Organization: Usenet Network
Message-ID: <20261121104234.98386-2-aniketgupta3001@gmail.com>
References: <20261121104234.98386-1-aniketgupta3001@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3393103"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:FLZcB90DXRxbvKRPAHSNmHYnplA= sha256:NcweA1g7Okd0UJqvPTT/q+TYBoosNpFOAQCW+emoMe8=
	sha1:b4ZLuWI/wOVukoO7oYancm8w3KE= sha256:OjDfAOknzLwM+0rnbpj+zNNeRfoeN/CLMx9YQQpTzzw=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id E764F115B53; Sat, 21 Nov 2026 13:42:58 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id zUFNd5TYumFp;
	Sat, 21 Nov 2026 13:42:55 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-76013-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 33D23115AC7; Sat, 21 Nov 2026 13:42:46 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id C7C8D35D38; Sat, 21 Nov 2026 10:42:45 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795257764;
	b=d8EThWukKtn1jWGZiNq1ocSO8Xd8T5tsONlmNO5lcut9/woVbSJ6aYix40VL1GwEKsrG
	 5KPHWQYNoq+4B9xDLWRn+hn/uyYLN0D6EOKBkazaZ0MiGhOteLblzFHJCXCNxEPN5Mhrb
	 fL2tSiEtRTiZI4rJWOkRDtifMUZhK0dqPmHwZjThTRzTMUddNjKjhKMlgfMT3zbl3eljg
	 juqA1CJtRi1LCdRyIwAGkBAKZbn5p8e7t9arYPvUDPntsOvjJlsKH8q4h6yrhiOPuumwW
	 JrP7CXF6n5ylSRH8S5mxhnMMWsehIzOx+303IvUZ8Bp3vYalf/L/VfqAPX8ZNTfnc4Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795257764;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
	 References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=yD+1+fPQOO4lGeFLvUY1kORUJlQlZEDmc8jcUQhjEhg=;
	b=JyuLbTiDiyGg2nON2V0Z60+1UixrE89kKC0W+GlP5aWmjrLuzuIDsfb4JCLkoFQlaNQM
	 GqD0Vd76MasgTErAHqEUCQuf5NCluopuGcl+IKD5I/QvFgjTPBJCzYMmUoRMxcunJqxqP
	 JLt7GeHa64ZHRbf54L77gqZ+6X/JftZYZb8sQA0LO4+hwu6k3qXvi91a0rXDN2gW8BV1G
	 G5irIafmxBbECP0x8PNs9Vya3e0mSA5cg10RaQ/58tlMHJ/wiIMgb6xDTKPVytJw7MHV+
	 7fFdHLTpB/HlrMx7xfGg2+4uE2cmKrWEe23iDS56+Eu18mbg1dpJtwRAchG1Cmw76Dw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=tHj5+nD4;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 3247F606A33D;
	Sat, 21 Nov 2026 10:42:44 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=tHj5+nD4
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.53
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795257763;
	b=FXzqKmodIvcoDL+mmlsE/F9N2tD05hifa/pL/QUmaAd6/YVq6ErN1UPGpAYria2gIwZf
	 4W+YJDZxt5QZ3X4ZOqQ+wgwD8xDlYPxWM2U5Fdb7kABACBIIYmkN2Ykm13UPi+A8JaWd8
	 CHPlk3CmhzenkoNxIJk91Mf1NXBxZZDjGkcoOu/T8mL4BT7G+zsMpgcMxfO39pHNccQxz
	 kZ5n7jb67Kyy0SsvVqEtvRQTBPwMuqHBrLbQQdaO9jtu6DLtSsRTNvJZyCNy/BQSr5ehS
	 sIv2JcHyS15rPI/LbXiWpaziMuVauAXI4+uewuA99jUn65x2tMPw+fqxcU9Pj6+tyJg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795257763;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=yD+1+fPQOO4lGeFLvUY1kORUJlQlZEDmc8jcUQhjEhg=;
	b=hi+DOUeKoXcBskw5p8Z4rAVimUPiiZMvhhvAA53Z/P5W9LiN+L11XyDtqliIcDgiLHHQ
	 uOdeaQ7Su9s4rl5ua01Et+VDJA4AKwXx8t1yU2xmQTrdc7dNmkZf9l0WGNiUh+2eW0ssW
	 Do9e2UYa4eQ1ByltJRb0GdLYyWs5/jn1emBWogZbfPNTviB4KZjdrB236ERe/RZxq5q0R
	 wOMx3RBoNhKXrql5NJY2H4kT+B+ERuW1js0zu8/PVaZfOD8B5Sd4WYY7AJTWShCZv3q29
	 XNmDNx0We38ZRxDlpf/MM+wgvjqoPvBCJfvGBQphTYCLbTSXiTxZ54B8ae1zugxPCRQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=tHj5+nD4;
	arc=none smtp.remote-ip=74.125.82.53
X-Received: from mail-dl1-f53.google.com (mail-dl1-f53.google.com [74.125.82.53])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05F5F606A339
	for <git@vger.kernel.org>; Sat, 21 Nov 2026 10:42:42 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 05F5F606A339
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dl1-f53.google.com with SMTP id a92af1059eb24-1b50a4bd2f3so2818697c88.1
        for <git@vger.kernel.org>; Sat, 21 Nov 2026 02:42:42 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1795257762; x=1795862562; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=yD+1+fPQOO4lGeFLvUY1kORUJlQlZEDmc8jcUQhjEhg=;
        b=tHj5+nD4NdMs51S5ZY/RRdFhrDuzOxutBerG/3dlYjsKRtXU+wWtKf8IDtGywzEOHg
         ffsELpHqrGSkAwfvNHluewAGg0iU9gEeYMpbmULSQKVSx9CmWQSKtlL1QRrs+iuGL23F
         MK7i8a8cqEP5+wdC03Cpz57WXEGpOwPeVJsGwH0ACkuiEurW9M7y8wMT9ybKonTrfywX
         w7WnAtF6MEX+5280AX/rvXvZ4fSrkZldfKPWpTJLX68sTTTnlUA0aVrk7c724nwCcAvQ
         T4ih2y3tRxQ1vOOXFoDL5f+D0Yh0m0aJP+BJ6Xf8eKM62P27H2xj673+Wfyyj1HHt/Ro
         nJPg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1795257762; x=1795862562;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to:content-type;
        bh=yD+1+fPQOO4lGeFLvUY1kORUJlQlZEDmc8jcUQhjEhg=;
        b=cpywxnpRrwIM8AWJSirQF0IwzZk85cGJQNcTmrzglX1q0veyNRqxhLzYeDAiA1Qjbo
         L3XzYx+cdJ5QrLpiQMGEe54M7ryvIBu7koIuGC73YTmQC3rbHGIdwhWixkMYTlfbLNSM
         GrlooWSNAcP3r/oRQwyj/VoXncGWiuai0v9ZXwXkbpQsZWE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1b6d with SMTP id a92af1059eb24-1b55689ab30mr6723320c88.17.1795257762080;
        Sat, 21 Nov 2026 02:42:42 -0800 (PST)
X-Received: from localhost.localdomain ([223.190.83.65])
        by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5568592adsm13290463c88.15.2026.11.21.02.42.39
        (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
        Sat, 21 Nov 2026 02:42:41 -0800 (PST)
X-Cc: Junio C Hamano <gitster@pobox.com>,
	Sami Jawhar <sami@theorem.dev>,
	Patrick Steinhardt <ps@pks.im>
X-Mailer: git-send-email 2.54.0
X-In-Reply-To: <20261121104234.98386-1-aniketgupta3001@gmail.com>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list