From patchwork Fri Jun 7 06:38:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13689342 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 7B756153597 for ; Fri, 7 Jun 2024 06:38:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717742292; cv=none; b=s9mOvwZ8k9wDzKhj9EW6m/ZMsrGs/zRKeyKhiQ084TCUBbhgUA6kkxPcc6CgKuzfEBkpNKJ9tJ9Z6ZB4v6xf0u83bV0RvEijc7t7RP3uYPN0gzPdv5296BwxQWFR4No4kghKU1lseKwBtPdqIldK1lsDCDl3NlBt4Kh+DKJe0FM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717742292; c=relaxed/simple; bh=mBD1yV5v6Qc01ynM9b4M9vwnyK63Ju1P4fBJWALtzhk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=E4gPN2sDug7ZXtxpAaZt7lq+C3xiLHczpaTH1sf3Lit+Hc+jEmFcgoGMqRVTaMuH/zy47igAjQyBC9w8k1JIWn4n0Z+4lWsyQMdMSmorp4OJ2jUSyZSpmYKTbDx4ppJPR7Nk4q9dRLdE4Cn0eWCTjHidLzDW2TSv6tOmi4lVbek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=cfn3E5Z/; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jkeuaerh; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="cfn3E5Z/"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jkeuaerh" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 8C29D138020E; Fri, 7 Jun 2024 02:38:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 07 Jun 2024 02:38:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=1717742290; x=1717828690; bh=4q4PWfLJjs 6+kd+eCY602TSkbi/6kT2IoiPLXb63WPw=; b=cfn3E5Z/C9hsun5xEphCpz8WAf 1+PZvJkbBtmUIBrKSNfZZDzZq3C5vh3ic1wZjq0+CvymwfFri2nfpv7NyVILQoxi tBMhUmSn8VlM3Ucu9/Zne1sHrnOBt/UIQ3Ie9gCv0GCuz9sUhw1f4h+Kw7i30zNe xmiFI/T1dVS7XVllSFLG9naVOVfxASHMJrt6LmC2oVTnxxqsuzBchWc9h2rNVK52 kDZfCM6YZgI69jP0TrDPxlJ78z7kiNnXoU6CZd6tew1kI7zRtvAJ3GxP+EhxunuU eyp/q6/C+VDpExvuIk49PMCKpnPYW4/mIlDmBnTCJHPShHFTdjo8+kg04XWg== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1717742290; x=1717828690; bh=4q4PWfLJjs6+kd+eCY602TSkbi/6 kT2IoiPLXb63WPw=; b=jkeuaerhWHkwzQvwAPTBmY3MkvgOAxmqk+K6L5qiKEez IevppAtg/iYIgjYPBno61cWomVh0QItkWypNz1YNCJ3Br4ZlLkc/dVs00KylD1ny 7wrifBz5ko+VE3awW9LK4kgTGyQ1TpQPWj3m1A3DlVBGY2a+KNl+bc6d+L3Gb2R9 ubmaNRYUEpjkETsvn8erk8kqV6PxXVKPiDvTqh0CzF6vSiC/tcPOmW4jeO6TG84H lu57SeTDMv1Owy6pylUYqwLl4NJzIIhT34m3mkKI2Rd/YOdd3wDJdJbFHxW6h4F3 +5pvk3b8Ztg2y/0FQKHEgUL9EgKwoV7ZMVsTy+USQA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelledguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Jun 2024 02:38:09 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id de38106f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Jun 2024 06:38:08 +0000 (UTC) Date: Fri, 7 Jun 2024 08:38:06 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Eric Sunshine Subject: [PATCH v6 07/27] diff: cast string constant in `fill_textconv()` Message-ID: <8ea984128d8aab8af08ba4f4be94452227672b4c.1717740366.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `fill_textconv()` function is responsible for converting an input file with a textconv driver, which is then passed to the caller. Weirdly though, the function also handles the case where there is no textconv driver at all. In that case, it will return either the contents of the populated filespec, or an empty string if the filespec is invalid. These two cases have differing memory ownership semantics. When there is a textconv driver, then the result is an allocated string. Otherwise, the result is either a string constant or owned by the filespec struct. All callers are in fact aware of this weirdness and only end up freeing the output buffer when they had a textconv driver. Ideally, we'd split up this interface to only perform the conversion via the textconv driver, and BUG in case the caller didn't provide one. This would make memory ownership semantics much more straight forward. For now though, let's simply cast the empty string constant to `char *` to avoid a warning with `-Wwrite-strings`. This is equivalent to the same cast that we already have in `fill_mmfile()`. Signed-off-by: Patrick Steinhardt --- diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff.c b/diff.c index ffd867ef6c..cecda216cf 100644 --- a/diff.c +++ b/diff.c @@ -7235,7 +7235,7 @@ size_t fill_textconv(struct repository *r, if (!driver) { if (!DIFF_FILE_VALID(df)) { - *outbuf = ""; + *outbuf = (char *) ""; return 0; } if (diff_populate_filespec(r, df, NULL))