🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #3713

Re: [PATCH v3 2/4] diff: use size_t for the allocation size of word-diff buffers

#3713
From: Phillip Wood
Date: Tue, 24 Nov 2026 17:02
55 lines
13048 bytes
Hi Elia

On 31/10/2026 10:16, Elia Pinto wrote:
> 
> @@ -2192,7 +2192,7 @@ static void diff_words_fill(struct diff_words_buffer *buffer, mmfile_t *out,
>   		regex_t *word_regex)
>   {
>   	int i, j;

I've added more context below where you can see that i and j are used as
offsets into buffer->text, so if we are making alloc a size_t, don't we
need to do the same for those and also buffer->orig_{nr,alloc}? There is
a complication though, i and j end up being converted regoff_t which is
"a signed integer type capable of storing the largest value that can be
stored in either an ptrdiff_t type or a ssize_t type". I think that
means they're likely to be bounded to INT_MAX on 32bit platforms which
makes supporting buffers larger than 2GB on those platforms tricky.

Thanks

Phillip


> -	long alloc = 0;
> +	size_t alloc = 0;
>   
>   	out->size = 0;
>   	out->ptr = NULL;

	/* fake an empty "0th" word */
	ALLOC_GROW(buffer->orig, 1, buffer->orig_alloc);
	buffer->orig[0].begin = buffer->orig[0].end = buffer->text.ptr;
	buffer->orig_nr = 1;

	for (i = 0; i < buffer->text.size; i++) {
		if (find_word_boundaries(&buffer->text, word_regex, &i, &j))
			return;

		/* store original boundaries */
		ALLOC_GROW(buffer->orig, buffer->orig_nr + 1,
				buffer->orig_alloc);
		buffer->orig[buffer->orig_nr].begin = buffer->text.ptr + i;
		buffer->orig[buffer->orig_nr].end = buffer->text.ptr + j;
		buffer->orig_nr++;

		/* store one word */
		ALLOC_GROW(out->ptr, out->size + j - i + 1, alloc);
		memcpy(out->ptr + out->size, buffer->text.ptr + i, j - i);
		out->ptr[out->size + j - i] = '\n';
		out->size += j - i + 1;

		i = j - 1;
	}
}
Technical Details
Message-ID: <9ff62027-f0a1-478f-b038-9ece951e6c17@gmail.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76231-linux-kernel-git=dewy.ru
References: <cover.1793352943.git.gitter.spiros@gmail.com> <cover.1793439137.git.gitter.spiros@gmail.com> <b27ef2a8882c2badb88d257ca28ed38b67c13c1b.1793439137.git.gitter.spiros@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76231-linux-kernel-git=dewy.ru
From: phillip.wood123@gmail.com (Phillip Wood)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v3 2/4] diff: use size_t for the allocation size of
 word-diff buffers
Date: Tue, 24 Nov 2026 17:02:57 +0000
Organization: Usenet Network
Message-ID: <9ff62027-f0a1-478f-b038-9ece951e6c17@gmail.com>
References: <cover.1793352943.git.gitter.spiros@gmail.com>
 <cover.1793439137.git.gitter.spiros@gmail.com>
 <b27ef2a8882c2badb88d257ca28ed38b67c13c1b.1793439137.git.gitter.spiros@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="4185443"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:9WHp2NxJRllEysAK5GY4ZxzeLKU= sha256:DfeMzV0u4ppfgMdPhFaRf1Vz2wbQwWwKtw7ouGLtJaI=
	sha1:XWM8oJCNvSLTlUF8YTSDE/ft+BA= sha256:l9Lb1mTMv/0oRBUOwzmbegYnIPWFvLh6zKSuCzhbc68=
Content-Language: en-US
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 BE00A125E29; Tue, 24 Nov 2026 20:03:10 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 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] 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 i9Prnkec5KZE;
	Tue, 24 Nov 2026 20:03:07 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76231-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 0064C125E2B; Tue, 24 Nov 2026 20:02:58 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 8172A2AC0F; Tue, 24 Nov 2026 17:02:57 +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=1795539777;
	b=QjjvWk85nqsDjEeYvxuqVuNRvLRNPio9Ju3r3R6c7e7jOpghMO5hSFT0P+sh2Lkmrb+j
	 lFIJcC8Xp/Tp9Fdi4AC/qzomzGfL4B62BWiKkLuGsXlO45R9OMboDS2WifFf8ob9U0hVu
	 TeFXnmO03hhr1rWXr4H0ps3Oc0oLEoGXKp27w/HWkR2CjAxf13JrwsbGIOH5KUe47zNY7
	 3Y6HezmGTftsMMOkipQwT+E2LYKeZWMLE0aNIWtljuLelLl5xxdOUC83CQHHpQBivsbB8
	 DWm3Cmd3c1DeZ+3eBuxqSARY22rUduvmlBzCPMowoohrauAQa+BGLi40qfiA2VHGhSw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795539777;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
	 X-Gm-Gg:X-Received:Received:Message-ID:Date:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:User-Agent:From:Subject:Reply-To:To:Cc:
	 References:Content-Language:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=TF7auDeQ29AW/Mq9zokPaF+HFqH/Pt8PSwTRwfNdgKA=;
	b=0L0ajUfO3scd6TkyZMGRuJn/eMfx917vKexZBcmPaBHrn5XQvQduQcklfiSKa3Lo2Drl
	 1sDO5Q5XL24JWV0CKzo8W26LJcArnNV2epPdNZpy523fYydjKveyoKfNFzb7UksYZDaJu
	 nTsvsRD2ZgO/h1LSk26cjDbI5LmhlF4wUUvjpiCQ5iGIiRp5b6ymObJsBoe54LHuMA7t7
	 dLTNBoby/UJGXghaUwFNj6rekkY8AY/dg1E+cVQmZhK7+J1wx0xJ0GoXqiYeZlqr1f36d
	 hvLQiy6zIzordpPKVRL8EX66OJ2j77m0wD+ZabsdK1a+RkM8I5wNZpPWLEMNz8okYCw==
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="p1sg/QGU";
	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 51902606A327;
	Tue, 24 Nov 2026 17:02:57 +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=p1sg/QGU
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.43
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795539776;
	b=vm7Pzryb7Id4QNLIPL+O3GU3C9gubNoATrqXHQif13WM6uJUqKGE8czr8j/vdiKC0xb5
	 QtNTCFM3xpqiiobVTlzD2wGFSvVdh9GlA/c8TYx1K/Fgv9DU+4+mldNymVSP6e8OxHJCf
	 uJKX104YxESOP8b/1zzFHV0j7gCcm8PcWq5kpRh6cIOixw+MWx5G+9y/qcFC0C+2REpzM
	 DntuRKn0WhQ2Ss40BcIJX/Wf6V5sHhtWMj3xzb6P7tEJxCAO27JWbsFzcQr1CBwPSFSn3
	 d8JJDyBroBQhTeS0G4KuYCnRiR/ItI3cfan9Rq9iXCs3FmAtKZp+OsLH9pdssxCBYjQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795539776;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 Message-ID:Date:MIME-Version:User-Agent:From:Subject:Reply-To:To:Cc:
	 References:Content-Language:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=TF7auDeQ29AW/Mq9zokPaF+HFqH/Pt8PSwTRwfNdgKA=;
	b=lhWIgOrwsELziMb1y6qz3beSrmqHedbwjtOS17VYr4xJ2ilt2yv1FUUIHrBcXHq5mfKB
	 Nyd+TUy2TLS08rYd51lrF9MAwL/37BDVanOXNfcfIcwVY50vMzeKB+SeuOWDjiFfUaojU
	 jmQDR4Fg2UvaCHoiaxsYf3sw7i+3nEImsXIs0tsVdObd54OH8S3BBPN32/6IRTZs2AWuH
	 AMPR6o/RKFqxyhYMy2rXgEhBwgxlQR5PvCpact9kJAR7dwm+2VJnk5w1F2qkR0O1AoDtg
	 oPN6mKWlXiBn3XfzeKTWMA4VrX07pu5lJIcuQJW4lbzg1ZikJP/dUiT6IOt8x493ZUw==
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="p1sg/QGU";
	arc=none smtp.remote-ip=209.85.221.43
X-Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43])
	(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 1D26B606A31E
	for <git@vger.kernel.org>; Tue, 24 Nov 2026 17:02:56 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1D26B606A31E
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-wr1-f43.google.com with SMTP id ffacd0b85a97d-491f34b4e0fso2223924f8f.2
        for <git@vger.kernel.org>; Tue, 24 Nov 2026 09:02:56 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1795539775; x=1796144575; darn=vger.kernel.org;
        h=content-transfer-encoding:content-type:in-reply-to:content-language
         :references:cc:to:reply-to:subject:from:user-agent:mime-version:date
         :message-id:from:to:cc:subject:date:message-id:reply-to:content-type;
        bh=TF7auDeQ29AW/Mq9zokPaF+HFqH/Pt8PSwTRwfNdgKA=;
        b=p1sg/QGUwx+Xx81oYrceoYmRONK8z8585b9C/0FKFzrtCaD73a5164aQyGKFrc+ida
         u6Wb9CaIiu2MbwnjwheP82Ok822WVsxrQnSJK9OCyVNzbPRcLS0vEuTh741q2uF1h3QD
         nnfkveLB3tNI/fTfJ+s/XNJJyq5Cl14Zo3Q+XVZ9WtHixaBbPPMPNNLnhHs+KMGGTaTb
         XaakSLFA5Fko1D/cNozDJG5H4/M1wcOW5vl/v3gM69lJUBmfDEiubUx6IvjSOjeJX2a+
         0LRfrag8w9KuSvhTtUW4obyEaJkrHVD/G53b/ETy0LhL/PxYDynxuPWdCSofIkmRgNsK
         fVMA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1795539775; x=1796144575;
        h=content-transfer-encoding:content-type:in-reply-to:content-language
         :references:cc:to:reply-to:subject:from:user-agent:mime-version:date
         :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=TF7auDeQ29AW/Mq9zokPaF+HFqH/Pt8PSwTRwfNdgKA=;
        b=2m2xhIiXbRQCf5x5AVe3y4kprelYNLka76e+ahXNgG1G7VRrJnBcg+I1EeIdgn3wc3
         QDrnmW3DuweOyC3l8xFCYeMXIEmDZJyu9CB87b8cV69ubkhYxMEAnJKPl3YnBibY5MyH
         I7YRKBQwaXLBC1AZzTwaVNqFnyawGjZEOYEcd1BSJgKDTEX0iio9H58Q6I9vW+Mb5vjQ
         Eor1ChbVMLaASSswInKK4lMsMEXvaI5cPQopsDy4eqs1vOjMp7wALVUpzF95/i/7iwQa
         VURR16QME0/x4Jtug71JzwI2ay09g4w3YHf7KazMCL+l0qHdKmJBrimdVrreCyLN3+GV
         YB0g==
X-Forwarded-Encrypted: i=1; AL+hErF/ZXOsb6bE6v8ewWmYRPXWYwBLp+mhcn/bbwgCslN0AwHXVb1Lj3rmeUAzLBJl6eWxEDc=@vger.kernel.org
X-Gm-Message-State: APuU4Z99g+VU0h4VAJ5VrOVXKEzqaSYMiCx3nPmuDkIvptS/X0oxL7Ns
	mkc1YMeGlYJ6kAew73Fs0qtA5vZiyR4eJhHfCtyEu0OKzWItjVlhXfe8
X-Gm-Gg: AZFdTZe953BC6RhLI0yvqzzyWDwYbudI7ctT2x55gIJKKEZcMWyK6J0YOgbSMZJFyxk
	s19+dyJzldURINZyvzIrWAxN8XRcfqte/A31Lj4YQw5NJ61nAFKf1rqmB1Jdx4vCC/1SOW0kLfm
	cjNt5c2P3fFRGjnBlolrxZXHSynMhNm4mGEcQv0C/nPP4CaAxMMwtXMagpDShPyszqyPWTNnsx5
	Mz2qdkKnIE09UtKBsw3yPw6FBcGcUGEie9qP6N8DX5n59YTEQiX3vaeFWjyCU67JXBHD/16Bab+
	HpKJKWZfEY4xiJgOgx6V1DHr3lXSoKwShBIPtDRyiP87OQqe9WqyhYXXGOpLQsdEXXPmKsz5NH6
	riZ54HyhihYAuF2sREjvqZSMXrGj5/vwvmynmMpKxTQdlFFUhX0ZB7AHk2FHwIhxzQwn8gpls9B
	xfK7V2YsRDKi+S+59KnsLtmTsAWfJCihHLeaj/8JvOmdqawP2CTrQKTz1lPQ31lkLAgtokRKEZf
	hMV17+YsAdEfUvkkK1GN/xNg8/cJhgllFK8NRzI0J0nEU/6KOYCcxUVfkTkKTsR//K2bSQDUCkR
	K1gsLiP9QyLOT+BlUGVbuAdLaku9s7vEer1KwzveH51lQvdLu9tFW3anROukhWSDDOnj8xj1RBJ
	fKC1SmNGCW/Tp
X-Received: by 2002:a05:6000:310a:b0:491:286f:8e63 with SMTP id ffacd0b85a97d-4abaf7401fdmr33806698f8f.14.1795539774414;
        Tue, 24 Nov 2026 09:02:54 -0800 (PST)
X-Received: from ?IPV6:2a0a:ef40:724:6601:5667:a2d8:e11c:6db1? ([2a0a:ef40:724:6601:5667:a2d8:e11c:6db1])
        by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6b2050f1sm28849615f8f.38.2026.11.24.09.02.52
        (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
        Tue, 24 Nov 2026 09:02:53 -0800 (PST)
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
X-User-Agent: Mozilla Thunderbird
X-Reply-To: phillip.wood@dunelm.org.uk
X-Cc: Patrick Steinhardt <ps@pks.im>,
 Johannes Schindelin <Johannes.Schindelin@gmx.de>, Jeff King <peff@peff.net>,
 Junio C Hamano <gitster@pobox.com>,
 Christian Couder <christian.couder@gmail.com>
X-In-Reply-To: <b27ef2a8882c2badb88d257ca28ed38b67c13c1b.1793439137.git.gitter.spiros@gmail.com>