From patchwork Sun Mar 24 11:21:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13600799 Received: from mout.web.de (mout.web.de [217.72.192.78]) (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 DA46928E7 for ; Sun, 24 Mar 2024 11:21:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.72.192.78 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711279286; cv=none; b=F2+PRkCA9DCRcneivh+gEbDbSZEGrAdioHXpoYkBzx3PSBcCgZpunD0zD40yJZC17xgY+uxZBIJcgGhrMcvuO8ow5r3C9Q26viphShVjafaC5Li0bCYz/rHQ2u+jL+qORHOqC9vXTrDPA/YdCWGg3g1m5c9eD1G1O5yKI5sglGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711279286; c=relaxed/simple; bh=KA7wZqU5i23ElsYPwQnSYv0NRwO/wUXarjhmXSLCHUg=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=f/o58UBeQjVy6TPNKv+6weN7e0rnqfmEHrtpLGwsGm/NIvoiBqYrTOG0sfppQm2gWsuXXh4y3KRvL1gVLhTNWKIQuEnmIBttVq4GeYUmaTT04xAvbG+b/8HC0xK9ssyU5Htid5clbrn94Xw/GNCm6B9ehK3J9u5wadnbUPAIWWY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b=j8UAVnyf; arc=none smtp.client-ip=217.72.192.78 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b="j8UAVnyf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1711279276; x=1711884076; i=l.s.r@web.de; bh=OAuwuF8NUXDIIDm6R0oEGUoTUFSF6z7eycIblSMacDk=; h=X-UI-Sender-Class:Date:Subject:From:To:References:In-Reply-To; b=j8UAVnyfdawRhJJNcvvzWWZ4G3dW2JqtzfIcoO6Yr2QVhhlqG5K8HYneZAnC8rHq cyMTdWw3SLnjillMH0tea4/wOGQi/GBfUiH5tR8+b76LXmMacCqVbnn5tsOFBQtZb B5dG9UgZCSwwWYRz+NenIzPn8MWNRhvXXKdnZ/lnOQ0u9clZczNl5xDRYS8xlu9/E 9V5xpRpg4oZNi+WyNrEkswmB4qNv/ybh6/1HSD9txRjT04n7rmHOSV3Sxc4ZbwlaW fEiDkIOQhaDeNl0nWUZDMnc1eAdYGIdHAAOGk9rvwuXUOeLJYCUqjI2CFiU2zbUuv anwtZIBSu+gKk7yLjw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.19.211]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MQPdr-1sAiHy4B9N-00MNOg for ; Sun, 24 Mar 2024 12:21:16 +0100 Message-ID: Date: Sun, 24 Mar 2024 12:21:15 +0100 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 2/2] cat-file: use strbuf_expand_bad_format() From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List References: <27cdcde7-74bc-4ee8-bc84-9a6046292cae@web.de> Content-Language: en-US In-Reply-To: <27cdcde7-74bc-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4Sr0lYsLnUykh6Sqg7bqTBkBTsctIr2Rzz472Wf35FFUDD0xq1otcBg1iDBo4hFsi cCNRwBUsAtKuzdF5tmlEhjI/yMTUPj+F7SVr8KjCkYfUQ= Report unknown format elements and missing closing parentheses with consistent and translated messages by calling strbuf_expand_bad_format() at the very end of the combined if/else chain of expand_format() and expand_atom(). Signed-off-by: René Scharfe --- Same as v1. builtin/cat-file.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) -- 2.44.0 diff --git a/builtin/cat-file.c b/builtin/cat-file.c index bbf851138e..fadf2da2f0 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -310,8 +310,8 @@ static int is_atom(const char *atom, const char *s, int slen) return alen == slen && !memcmp(atom, s, alen); } -static void expand_atom(struct strbuf *sb, const char *atom, int len, - struct expand_data *data) +static int expand_atom(struct strbuf *sb, const char *atom, int len, + struct expand_data *data) { if (is_atom("objectname", atom, len)) { if (!data->mark_query) @@ -343,7 +343,8 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len, strbuf_addstr(sb, oid_to_hex(&data->delta_base_oid)); } else - die("unknown format element: %.*s", len, atom); + return 0; + return 1; } static void expand_format(struct strbuf *sb, const char *start, @@ -354,12 +355,11 @@ static void expand_format(struct strbuf *sb, const char *start, if (skip_prefix(start, "%", &start) || *start != '(') strbuf_addch(sb, '%'); - else if (!(end = strchr(start + 1, ')'))) - die("format element '%s' does not end in ')'", start); - else { - expand_atom(sb, start + 1, end - start - 1, data); + else if ((end = strchr(start + 1, ')')) && + expand_atom(sb, start + 1, end - start - 1, data)) start = end + 1; - } + else + strbuf_expand_bad_format(start, "cat-file"); } }