From patchwork Thu May 30 12:51:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13680365 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (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 BDF0216D4FC for ; Thu, 30 May 2024 12:51:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717073474; cv=none; b=J5HNLKR9+94nlhH4369wOH0ZBGylyMoaBuvMGDCFj9MVko4nBJ5FWkig/MMBxcLS+7TqUzvlVL4/3FI2X66IW7wXep3u98nfcEEhg7bRnchUpRxkAJSe9bIOqelFik/cf5Si8B2tHrd9RRzE9nw8hkgyzZ+lv1ZGs/NmHIYVMFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717073474; c=relaxed/simple; bh=TqVp/5qSq/BhPOUg2+WBnLpb52RMdQmQNtiL9Ehh0c8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=poLdIAMMH6Iw8joLcr90sFiXYR+6uuRw63ynGE8NtqhR+cn9TkpUVHnOVBQL9/mO7lREGXI+XynHBodEG50iFp6NYWwiZ2ZQAQHTcchTrbv7ob3dmBtfcA8ojMDtf1JqCwv2vaPJeXJKhXobKPBCYiKEimAU+H4qSBzwm/fkGUc= 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=SpA76QWX; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZNUPZh5w; arc=none smtp.client-ip=103.168.172.156 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="SpA76QWX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZNUPZh5w" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id C11B41140157; Thu, 30 May 2024 08:51:11 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 30 May 2024 08:51:11 -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=1717073471; x=1717159871; bh=qMB34Ngz4c RGU52Ks21UAzbkVcq6eGyDGIWJVDYpSJc=; b=SpA76QWXR+gS5EPM2NEOpDcW3H zWmvmuA2s22HmX2Jo5QE9qY9A/ghwYLs8LDZbQvd2zW9+19x2dFbrWA0orRkBjoy jrbBPjYNsT5e0eBY7jYGq9MSSNoznNAia+Cmd1l11wG3T2m062wBmXRmXJn6WfML FD7G9blPhpX1QXV8LgPuar6gPhT7LL4u8yIVXpU9ZKotuNMsgzb9l7LYUZ8NkTQ9 g5u+vB7KOTB7r+AFikEQ74O06McGoQFLa1Md7U2XM5zUDXDZeOcoClE7+EoRqtaI avHQnCaHs4MAXpRqprdWCvs9ACTLni9di1vr/JYNTDNwxgzex1za/aX5MFZQ== 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=1717073471; x=1717159871; bh=qMB34Ngz4cRGU52Ks21UAzbkVcq6 eGyDGIWJVDYpSJc=; b=ZNUPZh5w81/1wYbrUUE7C8o6Fphi8RanPN951Q4JWKcF W5dQ0aoIPXZskvtc/z1FYUchapFOhvO0XY8HMWQ9bCbBLqqIts3iNz/TwB7IWT46 Z64iif0j+E55yKAaoIDldQAgneVR217moRtoJXqyuthn/Lc29wzO/PRI+6Rh1eMB IHhSEqUeCPdXnPlRHoDhNnHxYaGyXyB1ZYWqBcUzJLA73SSAjnEZi0AgzmgHx9vj OdjSjffyyql2QOXfR5ya2FMXRWp0xIw6l8WMWVPLVhNMcvZ5XiR5I/PubMzEMtuK 0qzh9StxlyujpTbMznWeuD0X9X1SAo+WHoUyKhLpmw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekgedgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 30 May 2024 08:51:10 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 04315bdf (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 30 May 2024 12:50:54 +0000 (UTC) Date: Thu, 30 May 2024 14:51:08 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH v2 08/19] object-file: make `buf` parameter of `index_mem()` a constant Message-ID: 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 `buf` parameter of `index_mem()` is a non-constant string. This will break once we enable `-Wwrite-strings` because we also pass constants from at least one callsite. Adapt the parameter to be a constant. As we cannot free the buffer without casting now, this also requires us to move the lifetime of the nested buffer around. Signed-off-by: Patrick Steinhardt --- object-file.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/object-file.c b/object-file.c index c9e374e57e..46ea00ac46 100644 --- a/object-file.c +++ b/object-file.c @@ -2483,12 +2483,13 @@ static int hash_format_check_report(struct fsck_options *opts UNUSED, } static int index_mem(struct index_state *istate, - struct object_id *oid, void *buf, size_t size, + struct object_id *oid, + const void *buf, size_t size, enum object_type type, const char *path, unsigned flags) { + struct strbuf nbuf = STRBUF_INIT; int ret = 0; - int re_allocated = 0; int write_object = flags & HASH_WRITE_OBJECT; if (!type) @@ -2498,11 +2499,10 @@ static int index_mem(struct index_state *istate, * Convert blobs to git internal format */ if ((type == OBJ_BLOB) && path) { - struct strbuf nbuf = STRBUF_INIT; if (convert_to_git(istate, path, buf, size, &nbuf, get_conv_flags(flags))) { - buf = strbuf_detach(&nbuf, &size); - re_allocated = 1; + buf = nbuf.buf; + size = nbuf.len; } } if (flags & HASH_FORMAT_CHECK) { @@ -2519,8 +2519,8 @@ static int index_mem(struct index_state *istate, ret = write_object_file(buf, size, type, oid); else hash_object_file(the_hash_algo, buf, size, type, oid); - if (re_allocated) - free(buf); + + strbuf_release(&nbuf); return ret; }