Received: from fhigh-b2-smtp.messagingengine.com (fhigh-b2-smtp.messagingengine.com [202.12.124.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB8974334DB for ; Tue, 28 Jul 2026 18:24:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.153 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785263047; cv=none; b=E3sSckLWtzwhmy5ILXC8xaW0uvk+biSzVSX0BRBIfyKipgRJ1fWA8ZD6SMMq6OzJAcKN9lsLOq436UAoOfrK4OZv39QIkMPVgSvGwqI0qA2tQiHV8lS3IJI3tQbjY5m3AerAzWqBP9+TSjoqc62MPg2fTDuDxQHKEnQa41M1PGw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785263047; c=relaxed/simple; bh=lIrtGDFpgiLHl1ZwpAI12LVseznxnl+hDKfOWvlvnyc=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=c0YAIxVoqOYHISD57SdkbKeaj8JTxWyHPuyDnnimJf0SjJQ0t6GnjyPhZfXCcGPl+v60adeoTjYLhz+9MOhsA4O/wLwZwa2btvqMvtluREajJjkZkV3hcyvA5PI4XL++Yy3cKP2BPkFzNuv27biELoFlUXhOKMHmGtWn3llE0uw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=YEhlbOeN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mV4UoC0G; arc=none smtp.client-ip=202.12.124.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="YEhlbOeN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mV4UoC0G" Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id EDECD7A0486; Tue, 28 Jul 2026 14:24:04 -0400 (EDT) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-03.internal (MEProxy); Tue, 28 Jul 2026 14:24:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1785263044; x=1785349444; bh=b/Dlf3q9KB ScDdgUj03FrKJzcKBUWyMrLzr41Bg36cs=; b=YEhlbOeNONTWLd2IR9EOeApsac S7nWbtAsYZHp5gHh6uX8DxfBsuonTf2Pb9PbFvN5HdPdxKEVMJFZ/EHxkrr/RdiN KEdMz9L9O2z+cF1jzFuUkQiZnfWv76QfbTtgKmHRP4y7ywNqf/hGwGOfqxkO8qOP gEDKDYgzkHqDbBgSDkXrl0c1L87hjmPy+Ftni/kVBtSPSXBfiV7DdE8ez6howba+ jKfGQ0PidCJJOgNJPVy6mMHCDaY2sKtlRRrM/ZXqXUpKQj7lq3rsuY1Vj1jqUVp0 ibq33KadmSl+sSYr9ZyiIhHFityFmJW/fGrZv/d8UplI06BgNmoZnIgYKQyA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1785263044; x=1785349444; bh=b/Dlf3q9KBScDdgUj03FrKJzcKBUWyMrLzr 41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QiHP1h2w X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 28 Jul 2026 14:24:04 -0400 (EDT) From: Junio C Hamano To: Phillip Wood Cc: Hardik Kumar , git@vger.kernel.org, =?utf-8?Q?Re?= =?utf-8?Q?n=C3=A9?= Scharfe , Patrick Steinhardt , Pablo Sabater Subject: Re: [PATCH v4] utf8: replace utf8_strwidth todo with descriptive comment In-Reply-To: (Phillip Wood's message of "Tue, 28 Jul 2026 16:41:11 +0100") References: <20260726123427.173877-1-hardikxk@gmail.com> <20260727211520.84289-1-hardikxk@gmail.com> Date: Tue, 28 Jul 2026 11:24:03 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Phillip Wood writes: > I don't think this comment, or the lines below add anything useful to > the message. It would be better to say something like > > As we do not want to change the return type, update the comment to > explain that and the need for the explicit cast. Perfect ;-) >> diff --git a/utf8.c b/utf8.c >> index 96460cc..1b55bd4 100644 >> --- a/utf8.c >> +++ b/utf8.c >> @@ -227,8 +227,9 @@ int utf8_strnwidth(const char *string, size_t len, int skip_ansi) >> } >> >> /* >> - * TODO: fix the interface of this function and `utf8_strwidth()` to >> - * return `size_t` instead of `int`. >> + * The function is used in multiple locations where the callers >> + * expect the result to be a signed int value. We cast the >> + * result to an int to avoid changing signatures of all callers. > > The last sentence does not really capture the reasons given in the > message of the commit that added this comment. If you haven't done so > already you should read it - see 937b71cc8b (utf8: fix overflow when > returning string width, 2022-12-01). The fundamental reason to call > cast_size_t_to_int(), rather than relying on an implicit conversion to > the return type, is not about changing signatures, it is about avoiding > an overflow that caused git to crash. The comment should also answer why the callers want an int, and whether that is a legitimate need. Topics the comment may want to cover include: - Callers want display width; we will never deal with output wider than 2 billion columns, so int is adequate, provided we do not cause bugs due to integer wraparound. - The return value is used to compute width in constructs like: printf("%*s", width, string) which requires int, not size_t. Instead of forcing these callers to call cast_size_t_to_int() individually, this function should return int after ensuring the value is correct without wraparound. This is in addition to explaining why we want cast_size_t_to_int(), as you described above. > When you send a new version of the patch please CC everyone who > commented on previous versions so they don't have to trawl the list to > find it. Thanks.