From patchwork Wed May 29 12:44:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678788 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 1DE88181322 for ; Wed, 29 May 2024 12:44:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986654; cv=none; b=TmhblfhKLMKpc8f3+HxSB8nJYazQXeBaNTzMcshV3Pe1dOaIOdJRRmzC8WpeFXci7xisVxkpSeDcL3RYpwUEW/ooAI0ZDByOd8jcpwC3y2PFtUgwQ7DBHPq3Bbd2bnHgNn9PrhYlThMc5x7rjV9sQpMRC6YA4AMecMqP55nusug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986654; c=relaxed/simple; bh=FtzDctyxoikwHnfwH3o8OSo1pXua0/g+/EcY3nZ2k04=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=husMe54ZSwKm7xO3L268O27o2CPSGW1qaiWcBn999PeF2g4yDh12sILRbrzyop7C+dfxgU8/jmcwCsuAhk7v+7pM2Cv3/bS3v5J90JE/Kx1oEmg5N8+1zXj1RKd1VJljDJ5v5hiIOHa/YUPw8iFZB1siwk+SH/1+T8Hdw80CBqM= 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=d3S8WZy1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XTZMdye3; arc=none smtp.client-ip=64.147.123.147 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="d3S8WZy1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XTZMdye3" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id 46FBF1C0012A; Wed, 29 May 2024 08:44:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 29 May 2024 08:44: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=1716986650; x=1717073050; bh=42SrNj2a1U kKWAZLOc0g00dav4MX7HzWabNGkIupVrg=; b=d3S8WZy1d67nIL3ehO00bnfhKm 4mfPryXObNdhgrfYZWosRvqrdJMzYMUYQpK+0LSf/puYCB/qPNJyetp3V3yOylgC kVQ7zB7IyJ0zZ03meE/FaTVw5cPYk3PHBackhbg6WRL4yInIxrLJj8QHyr48Nm4o 2S1z9sdrdeiFYOlP/gFEVN0NuhcR8aZJg5g4JvQ6UfaFDi7wb9qfNhRKAy4s9vh2 OLMMhfSv5pznd0PpXP8l+zHXBEoCbxLLTDaF26VaCa1sDplN8d6oOPX/CV6p4zxh BnfmFCVzZqKqp7pIWuuNg66JJNVckPzgUSiArRXTSBdOACbuLXPv18WuPmmg== 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=1716986650; x=1717073050; bh=42SrNj2a1UkKWAZLOc0g00dav4MX 7HzWabNGkIupVrg=; b=XTZMdye3BSeCYE7oExrP8N7sWA7wqXz9jwezRu9gXVAz XOfVPZiCV7g4B1zrBRkyZYTaL9Cp7Axgh+hCUGOC8Urw3J+QAIY3pt05y5PB6r3t pxRITEzxR7i734oiE4ACKnsC50NdhVa1cEwJ2zcJAtSeSmGVUEwegQyX76/PKNny 4nPLfT1/Jn/oanFt8fGQI8VjqVJsJB1H81MbiyVXht8dcwyqpkL7BvOgF74SLRN6 4w1/QUDkVxVVDDrs1EgwSeAPHiYT9pkFHNivke4gj3zmaSxcxPJrMPdHeeKj2wNf xmmv6ungm25Fo0LWsmUKyqSa8zgam0wBC4PpsB2rTA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:44:09 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id ffb762cf (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:43:55 +0000 (UTC) Date: Wed, 29 May 2024 14:44:07 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 01/19] global: improve const correctness when assigning string constants Message-ID: <25c31e550fcecdda7510b259b271cd45d036f5d7.1716983704.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: We're about to enable `-Wwrite-strings`, which changes the type of string constants to `const char[]`. Fix various sites where we assign such constants to non-const variables. Signed-off-by: Patrick Steinhardt --- builtin/bisect.c | 3 ++- builtin/blame.c | 2 +- builtin/bugreport.c | 2 +- builtin/check-ignore.c | 4 +-- builtin/clone.c | 6 ++--- builtin/commit.c | 6 ++--- builtin/diagnose.c | 2 +- builtin/log.c | 2 +- builtin/mailsplit.c | 4 +-- builtin/pull.c | 52 ++++++++++++++++++------------------ builtin/receive-pack.c | 4 +-- builtin/revert.c | 2 +- compat/regex/regcomp.c | 2 +- diff.c | 4 +-- diffcore-rename.c | 6 ++--- fmt-merge-msg.c | 2 +- fsck.c | 2 +- fsck.h | 2 +- gpg-interface.c | 2 +- http-backend.c | 2 +- imap-send.c | 6 ++--- pretty.c | 2 +- refs.c | 2 +- refs.h | 2 +- reftable/record.c | 6 ++--- run-command.c | 2 +- t/helper/test-hashmap.c | 3 ++- t/helper/test-json-writer.c | 10 +++---- t/helper/test-regex.c | 4 +-- t/helper/test-rot13-filter.c | 5 ++-- t/unit-tests/t-strbuf.c | 10 ++++--- trailer.c | 2 +- wt-status.c | 2 +- 33 files changed, 86 insertions(+), 81 deletions(-) diff --git a/builtin/bisect.c b/builtin/bisect.c index a58432b9d9..dabce9b542 100644 --- a/builtin/bisect.c +++ b/builtin/bisect.c @@ -262,7 +262,8 @@ static int bisect_reset(const char *commit) return bisect_clean_state(); } -static void log_commit(FILE *fp, char *fmt, const char *state, +static void log_commit(FILE *fp, + const char *fmt, const char *state, struct commit *commit) { struct pretty_print_context pp = {0}; diff --git a/builtin/blame.c b/builtin/blame.c index 838cd476be..98c7629b6a 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -134,7 +134,7 @@ static void get_ac_line(const char *inbuf, const char *what, { struct ident_split ident; size_t len, maillen, namelen; - char *tmp, *endp; + const char *tmp, *endp; const char *namebuf, *mailbuf; tmp = strstr(inbuf, what); diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 25f860a0d9..b3cc77af53 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -107,7 +107,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) struct tm tm; enum diagnose_mode diagnose = DIAGNOSE_NONE; char *option_output = NULL; - char *option_suffix = "%Y-%m-%d-%H%M"; + const char *option_suffix = "%Y-%m-%d-%H%M"; const char *user_relative_path = NULL; char *prefixed_filename; size_t output_path_len; diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c index 6c43430ec4..2bda6a1d46 100644 --- a/builtin/check-ignore.c +++ b/builtin/check-ignore.c @@ -35,8 +35,8 @@ static const struct option check_ignore_options[] = { static void output_pattern(const char *path, struct path_pattern *pattern) { - char *bang = (pattern && pattern->flags & PATTERN_FLAG_NEGATIVE) ? "!" : ""; - char *slash = (pattern && pattern->flags & PATTERN_FLAG_MUSTBEDIR) ? "/" : ""; + const char *bang = (pattern && pattern->flags & PATTERN_FLAG_NEGATIVE) ? "!" : ""; + const char *slash = (pattern && pattern->flags & PATTERN_FLAG_MUSTBEDIR) ? "/" : ""; if (!nul_term_line) { if (!verbose) { write_name_quoted(path, stdout, '\n'); diff --git a/builtin/clone.c b/builtin/clone.c index 23993b905b..92ab7d7165 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -71,7 +71,7 @@ static char *option_branch = NULL; static struct string_list option_not = STRING_LIST_INIT_NODUP; static const char *real_git_dir; static const char *ref_format; -static char *option_upload_pack = "git-upload-pack"; +static const char *option_upload_pack = "git-upload-pack"; static int option_verbosity; static int option_progress = -1; static int option_sparse_checkout; @@ -177,8 +177,8 @@ static struct option builtin_clone_options[] = { static const char *get_repo_path_1(struct strbuf *path, int *is_bundle) { - static char *suffix[] = { "/.git", "", ".git/.git", ".git" }; - static char *bundle_suffix[] = { ".bundle", "" }; + static const char *suffix[] = { "/.git", "", ".git/.git", ".git" }; + static const char *bundle_suffix[] = { ".bundle", "" }; size_t baselen = path->len; struct stat st; int i; diff --git a/builtin/commit.c b/builtin/commit.c index f53e7e86ff..75c741173e 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -113,7 +113,7 @@ static char *template_file; * the commit message and/or authorship. */ static const char *author_message, *author_message_buffer; -static char *edit_message, *use_message; +static const char *edit_message, *use_message; static char *fixup_message, *fixup_commit, *squash_message; static const char *fixup_prefix; static int all, also, interactive, patch_interactive, only, amend, signoff; @@ -121,8 +121,8 @@ static int edit_flag = -1; /* unspecified */ static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship; static int config_commit_verbose = -1; /* unspecified */ static int no_post_rewrite, allow_empty_message, pathspec_file_nul; -static char *untracked_files_arg, *force_date, *ignore_submodule_arg, *ignored_arg; -static char *sign_commit, *pathspec_from_file; +static const char *untracked_files_arg, *force_date, *ignore_submodule_arg, *ignored_arg; +static const char *sign_commit, *pathspec_from_file; static struct strvec trailer_args = STRVEC_INIT; /* diff --git a/builtin/diagnose.c b/builtin/diagnose.c index 4f22eb2b55..4857a4395b 100644 --- a/builtin/diagnose.c +++ b/builtin/diagnose.c @@ -18,7 +18,7 @@ int cmd_diagnose(int argc, const char **argv, const char *prefix) struct tm tm; enum diagnose_mode mode = DIAGNOSE_STATS; char *option_output = NULL; - char *option_suffix = "%Y-%m-%d-%H%M"; + const char *option_suffix = "%Y-%m-%d-%H%M"; char *prefixed_filename; const struct option diagnose_options[] = { diff --git a/builtin/log.c b/builtin/log.c index 78a247d8a9..b8846a9458 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1283,7 +1283,7 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids) o2->flags = flags2; } -static void gen_message_id(struct rev_info *info, char *base) +static void gen_message_id(struct rev_info *info, const char *base) { struct strbuf buf = STRBUF_INIT; strbuf_addf(&buf, "%s.%"PRItime".git.%s", base, diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c index 3af9ddb8ae..fe6dbc5d05 100644 --- a/builtin/mailsplit.c +++ b/builtin/mailsplit.c @@ -113,8 +113,8 @@ static int populate_maildir_list(struct string_list *list, const char *path) DIR *dir; struct dirent *dent; char *name = NULL; - char *subs[] = { "cur", "new", NULL }; - char **sub; + const char *subs[] = { "cur", "new", NULL }; + const char **sub; int ret = -1; for (sub = subs; *sub; ++sub) { diff --git a/builtin/pull.c b/builtin/pull.c index d622202bce..2d0429f14f 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -71,48 +71,48 @@ static const char * const pull_usage[] = { /* Shared options */ static int opt_verbosity; -static char *opt_progress; +static const char *opt_progress; static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT; static int recurse_submodules_cli = RECURSE_SUBMODULES_DEFAULT; /* Options passed to git-merge or git-rebase */ static enum rebase_type opt_rebase = -1; -static char *opt_diffstat; -static char *opt_log; -static char *opt_signoff; -static char *opt_squash; -static char *opt_commit; -static char *opt_edit; -static char *cleanup_arg; -static char *opt_ff; -static char *opt_verify_signatures; -static char *opt_verify; +static const char *opt_diffstat; +static const char *opt_log; +static const char *opt_signoff; +static const char *opt_squash; +static const char *opt_commit; +static const char *opt_edit; +static const char *cleanup_arg; +static const char *opt_ff; +static const char *opt_verify_signatures; +static const char *opt_verify; static int opt_autostash = -1; static int config_autostash; static int check_trust_level = 1; static struct strvec opt_strategies = STRVEC_INIT; static struct strvec opt_strategy_opts = STRVEC_INIT; -static char *opt_gpg_sign; +static const char *opt_gpg_sign; static int opt_allow_unrelated_histories; /* Options passed to git-fetch */ -static char *opt_all; -static char *opt_append; -static char *opt_upload_pack; +static const char *opt_all; +static const char *opt_append; +static const char *opt_upload_pack; static int opt_force; -static char *opt_tags; -static char *opt_prune; -static char *max_children; +static const char *opt_tags; +static const char *opt_prune; +static const char *max_children; static int opt_dry_run; -static char *opt_keep; -static char *opt_depth; -static char *opt_unshallow; -static char *opt_update_shallow; -static char *opt_refmap; -static char *opt_ipv4; -static char *opt_ipv6; +static const char *opt_keep; +static const char *opt_depth; +static const char *opt_unshallow; +static const char *opt_update_shallow; +static const char *opt_refmap; +static const char *opt_ipv4; +static const char *opt_ipv6; static int opt_show_forced_updates = -1; -static char *set_upstream; +static const char *set_upstream; static struct strvec opt_fetch = STRVEC_INIT; static struct option pull_options[] = { diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 01c1f04ece..c8d12ee0a7 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1249,7 +1249,7 @@ static int run_proc_receive_hook(struct command *commands, return code; } -static char *refuse_unconfigured_deny_msg = +static const char *refuse_unconfigured_deny_msg = N_("By default, updating the current branch in a non-bare repository\n" "is denied, because it will make the index and work tree inconsistent\n" "with what you pushed, and will require 'git reset --hard' to match\n" @@ -1269,7 +1269,7 @@ static void refuse_unconfigured_deny(void) rp_error("%s", _(refuse_unconfigured_deny_msg)); } -static char *refuse_unconfigured_deny_delete_current_msg = +static const char *refuse_unconfigured_deny_delete_current_msg = N_("By default, deleting the current branch is denied, because the next\n" "'git clone' won't result in any file checked out, causing confusion.\n" "\n" diff --git a/builtin/revert.c b/builtin/revert.c index 53935d2c68..7bf2b4e11d 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -179,7 +179,7 @@ static int run_sequencer(int argc, const char **argv, const char *prefix, /* Check for incompatible command line arguments */ if (cmd) { - char *this_operation; + const char *this_operation; if (cmd == 'q') this_operation = "--quit"; else if (cmd == 'c') diff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c index 2bc0f1187a..6c5d455e92 100644 --- a/compat/regex/regcomp.c +++ b/compat/regex/regcomp.c @@ -848,7 +848,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len) { unsigned int table_size; #ifndef _LIBC - char *codeset_name; + const char *codeset_name; #endif memset (dfa, '\0', sizeof (re_dfa_t)); diff --git a/diff.c b/diff.c index e70301df76..ffd867ef6c 100644 --- a/diff.c +++ b/diff.c @@ -3764,7 +3764,7 @@ static void builtin_diff(const char *name_a, return; } -static char *get_compact_summary(const struct diff_filepair *p, int is_renamed) +static const char *get_compact_summary(const struct diff_filepair *p, int is_renamed) { if (!is_renamed) { if (p->status == DIFF_STATUS_ADDED) { @@ -4076,7 +4076,7 @@ static int reuse_worktree_file(struct index_state *istate, static int diff_populate_gitlink(struct diff_filespec *s, int size_only) { struct strbuf buf = STRBUF_INIT; - char *dirty = ""; + const char *dirty = ""; /* Are we looking at the work tree? */ if (s->dirty_submodule) diff --git a/diffcore-rename.c b/diffcore-rename.c index 5a6e2bcac7..0e1adb87df 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -406,7 +406,7 @@ static const char *get_highest_rename_path(struct strintmap *counts) return highest_destination_dir; } -static char *UNKNOWN_DIR = "/"; /* placeholder -- short, illegal directory */ +static const char *UNKNOWN_DIR = "/"; /* placeholder -- short, illegal directory */ static int dir_rename_already_determinable(struct strintmap *counts) { @@ -429,8 +429,8 @@ static int dir_rename_already_determinable(struct strintmap *counts) } static void increment_count(struct dir_rename_info *info, - char *old_dir, - char *new_dir) + const char *old_dir, + const char *new_dir) { struct strintmap *counts; struct strmap_entry *e; diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c index 7d144b803a..5af63ab5ab 100644 --- a/fmt-merge-msg.c +++ b/fmt-merge-msg.c @@ -447,7 +447,7 @@ static void fmt_merge_msg_title(struct strbuf *out, const char *current_branch) { int i = 0; - char *sep = ""; + const char *sep = ""; strbuf_addstr(out, "Merge "); for (i = 0; i < srcs.nr; i++) { diff --git a/fsck.c b/fsck.c index 7dff41413e..61cd48aa25 100644 --- a/fsck.c +++ b/fsck.c @@ -1231,7 +1231,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size, } int fsck_buffer(const struct object_id *oid, enum object_type type, - void *data, unsigned long size, + const void *data, unsigned long size, struct fsck_options *options) { if (type == OBJ_BLOB) diff --git a/fsck.h b/fsck.h index 17fa2dda5d..4f0c4e6479 100644 --- a/fsck.h +++ b/fsck.h @@ -202,7 +202,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size, * struct. */ int fsck_buffer(const struct object_id *oid, enum object_type, - void *data, unsigned long size, + const void *data, unsigned long size, struct fsck_options *options); /* diff --git a/gpg-interface.c b/gpg-interface.c index 5193223714..71a9382a61 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -727,7 +727,7 @@ static int git_gpg_config(const char *var, const char *value, void *cb UNUSED) { struct gpg_format *fmt = NULL; - char *fmtname = NULL; + const char *fmtname = NULL; char *trust; int ret; diff --git a/http-backend.c b/http-backend.c index 5b65287ac9..5b4dca65ed 100644 --- a/http-backend.c +++ b/http-backend.c @@ -753,7 +753,7 @@ static int bad_request(struct strbuf *hdr, const struct service_cmd *c) int cmd_main(int argc UNUSED, const char **argv UNUSED) { - char *method = getenv("REQUEST_METHOD"); + const char *method = getenv("REQUEST_METHOD"); const char *proto_header; char *dir; struct service_cmd *cmd = NULL; diff --git a/imap-send.c b/imap-send.c index a5d1510180..8b723b34a5 100644 --- a/imap-send.c +++ b/imap-send.c @@ -1215,9 +1215,9 @@ static int imap_store_msg(struct imap_store *ctx, struct strbuf *msg) static void wrap_in_html(struct strbuf *msg) { struct strbuf buf = STRBUF_INIT; - static char *content_type = "Content-Type: text/html;\n"; - static char *pre_open = "
\n";
-	static char *pre_close = "
\n"; + static const char *content_type = "Content-Type: text/html;\n"; + static const char *pre_open = "
\n";
+	static const char *pre_close = "
\n"; const char *body = strstr(msg->buf, "\n\n"); if (!body) diff --git a/pretty.c b/pretty.c index 22a81506b7..ec05db5655 100644 --- a/pretty.c +++ b/pretty.c @@ -1325,7 +1325,7 @@ int format_set_trailers_options(struct process_trailer_options *opts, static size_t parse_describe_args(const char *start, struct strvec *args) { struct { - char *name; + const char *name; enum { DESCRIBE_ARG_BOOL, DESCRIBE_ARG_INTEGER, diff --git a/refs.c b/refs.c index 8260c27cde..292e8d947e 100644 --- a/refs.c +++ b/refs.c @@ -159,7 +159,7 @@ void update_ref_namespace(enum ref_namespace namespace, char *ref) { struct ref_namespace_info *info = &ref_namespace[namespace]; if (info->ref_updated) - free(info->ref); + free((char *)info->ref); info->ref = ref; info->ref_updated = 1; } diff --git a/refs.h b/refs.h index 34568ee1fb..923f751d18 100644 --- a/refs.h +++ b/refs.h @@ -975,7 +975,7 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt); */ struct ref_namespace_info { - char *ref; + const char *ref; enum decoration_type decoration; /* diff --git a/reftable/record.c b/reftable/record.c index 5506f3e913..a2cba5ef74 100644 --- a/reftable/record.c +++ b/reftable/record.c @@ -116,7 +116,7 @@ static int decode_string(struct strbuf *dest, struct string_view in) return start_len - in.len; } -static int encode_string(char *str, struct string_view s) +static int encode_string(const char *str, struct string_view s) { struct string_view start = s; int l = strlen(str); @@ -969,9 +969,9 @@ static int reftable_log_record_decode(void *rec, struct strbuf key, return REFTABLE_FORMAT_ERROR; } -static int null_streq(char *a, char *b) +static int null_streq(const char *a, const char *b) { - char *empty = ""; + const char *empty = ""; if (!a) a = empty; diff --git a/run-command.c b/run-command.c index 1b821042b4..7600531fb6 100644 --- a/run-command.c +++ b/run-command.c @@ -663,7 +663,7 @@ int start_command(struct child_process *cmd) int need_in, need_out, need_err; int fdin[2], fdout[2], fderr[2]; int failed_errno; - char *str; + const char *str; /* * In case of errors we must keep the promise to close FDs diff --git a/t/helper/test-hashmap.c b/t/helper/test-hashmap.c index 0eb0b3d49c..2912899558 100644 --- a/t/helper/test-hashmap.c +++ b/t/helper/test-hashmap.c @@ -36,7 +36,8 @@ static int test_entry_cmp(const void *cmp_data, } static struct test_entry *alloc_test_entry(unsigned int hash, - char *key, char *value) + const char *key, + const char *value) { size_t klen = strlen(key); size_t vlen = strlen(value); diff --git a/t/helper/test-json-writer.c b/t/helper/test-json-writer.c index afe393f597..ed52eb76bf 100644 --- a/t/helper/test-json-writer.c +++ b/t/helper/test-json-writer.c @@ -174,7 +174,7 @@ static void make_arr4(int pretty) jw_end(&arr4); } -static char *expect_nest1 = +static const char *expect_nest1 = "{\"obj1\":{\"a\":\"abc\",\"b\":42,\"c\":true},\"arr1\":[\"abc\",42,true]}"; static struct json_writer nest1 = JSON_WRITER_INIT; @@ -195,10 +195,10 @@ static void make_nest1(int pretty) jw_release(&arr1); } -static char *expect_inline1 = +static const char *expect_inline1 = "{\"obj1\":{\"a\":\"abc\",\"b\":42,\"c\":true},\"arr1\":[\"abc\",42,true]}"; -static char *pretty_inline1 = +static const char *pretty_inline1 = ("{\n" " \"obj1\": {\n" " \"a\": \"abc\",\n" @@ -236,10 +236,10 @@ static void make_inline1(int pretty) jw_end(&inline1); } -static char *expect_inline2 = +static const char *expect_inline2 = "[[1,2],[3,4],{\"a\":\"abc\"}]"; -static char *pretty_inline2 = +static const char *pretty_inline2 = ("[\n" " [\n" " 1,\n" diff --git a/t/helper/test-regex.c b/t/helper/test-regex.c index 80042eafc2..366bd70976 100644 --- a/t/helper/test-regex.c +++ b/t/helper/test-regex.c @@ -20,8 +20,8 @@ static struct reg_flag reg_flags[] = { static int test_regex_bug(void) { - char *pat = "[^={} \t]+"; - char *str = "={}\nfred"; + const char *pat = "[^={} \t]+"; + const char *str = "={}\nfred"; regex_t r; regmatch_t m[1]; diff --git a/t/helper/test-rot13-filter.c b/t/helper/test-rot13-filter.c index f8d564c622..7e1d9e0ee4 100644 --- a/t/helper/test-rot13-filter.c +++ b/t/helper/test-rot13-filter.c @@ -136,7 +136,7 @@ static void free_delay_entries(void) strmap_clear(&delay, 0); } -static void add_delay_entry(char *pathname, int count, int requested) +static void add_delay_entry(const char *pathname, int count, int requested) { struct delay_entry *entry = xcalloc(1, sizeof(*entry)); entry->count = count; @@ -189,7 +189,8 @@ static void reply_list_available_blobs_cmd(void) static void command_loop(void) { for (;;) { - char *buf, *output; + char *buf; + const char *output; char *pathname; struct delay_entry *entry; struct strbuf input = STRBUF_INIT; diff --git a/t/unit-tests/t-strbuf.c b/t/unit-tests/t-strbuf.c index de434a4441..6027dafef7 100644 --- a/t/unit-tests/t-strbuf.c +++ b/t/unit-tests/t-strbuf.c @@ -2,7 +2,8 @@ #include "strbuf.h" /* wrapper that supplies tests with an empty, initialized strbuf */ -static void setup(void (*f)(struct strbuf*, void*), void *data) +static void setup(void (*f)(struct strbuf*, const void*), + const void *data) { struct strbuf buf = STRBUF_INIT; @@ -13,7 +14,8 @@ static void setup(void (*f)(struct strbuf*, void*), void *data) } /* wrapper that supplies tests with a populated, initialized strbuf */ -static void setup_populated(void (*f)(struct strbuf*, void*), char *init_str, void *data) +static void setup_populated(void (*f)(struct strbuf*, const void*), + const char *init_str, const void *data) { struct strbuf buf = STRBUF_INIT; @@ -64,7 +66,7 @@ static void t_dynamic_init(void) strbuf_release(&buf); } -static void t_addch(struct strbuf *buf, void *data) +static void t_addch(struct strbuf *buf, const void *data) { const char *p_ch = data; const char ch = *p_ch; @@ -83,7 +85,7 @@ static void t_addch(struct strbuf *buf, void *data) check_char(buf->buf[buf->len], ==, '\0'); } -static void t_addstr(struct strbuf *buf, void *data) +static void t_addstr(struct strbuf *buf, const void *data) { const char *text = data; size_t len = strlen(text); diff --git a/trailer.c b/trailer.c index 2bcb9ba8f7..72e5136c73 100644 --- a/trailer.c +++ b/trailer.c @@ -63,7 +63,7 @@ struct arg_item { static LIST_HEAD(conf_head); -static char *separators = ":"; +static const char *separators = ":"; static int configured; diff --git a/wt-status.c b/wt-status.c index ff4be071ca..7912545e4e 100644 --- a/wt-status.c +++ b/wt-status.c @@ -2408,7 +2408,7 @@ static void wt_porcelain_v2_print_unmerged_entry( int mode; struct object_id oid; } stages[3]; - char *key; + const char *key; char submodule_token[5]; char unmerged_prefix = 'u'; char eol_char = s->null_termination ? '\0' : '\n'; From patchwork Wed May 29 12:44:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678789 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 C90F6181B95 for ; Wed, 29 May 2024 12:44:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986657; cv=none; b=ebafhHSOjlwx4lz0uQyJqBSUfnucbubTkwcOh313LNtWy4R/444YH9LrUF0F0dc7WeizGDbWP80Nuq3WBWbywKgsZV7ABsDT98CqrAuiGgxf76i90VIMBzdXlEx+IqnQ2fECsXUOwhZA/I9my82/T+znkbzpzRvxSinnsUJOoIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986657; c=relaxed/simple; bh=RuZlLmGEsvttBhmFeEMJ4pT3fq3CUXXasLzvj/y9++I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lPoNFsUGErdfsZxT50GcDVn0hakzmyl4TV4NfB0DDekEmtEI0wJpXBFl4D26a83JD2Qs3MLZ6tez/yWDz02tmhiZf3N09oK0b8SuP2e6nNBM6RY626ZD+wHxjN2kW6tJQ0DMt4miXZB1/U2GGCX++/D6UJiv01fbAFdRTcCFRlk= 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=QvkwbK7I; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jPiohkZp; arc=none smtp.client-ip=64.147.123.147 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="QvkwbK7I"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jPiohkZp" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id 1361A1C000BF; Wed, 29 May 2024 08:44:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 29 May 2024 08:44:15 -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=1716986654; x=1717073054; bh=JKuNXmKf0x 8jkd+E4OJ5ht5rWpKYN4jbdROqCmu6FgI=; b=QvkwbK7ItTmBKxSd9sjDv27a25 Crwc1Hzor9mGjj9T6UM1hkI3Ig5kn0taOeuuUN5ddsxS2v9VNQJHs/pZlCEWt2OC 65Ctc1Zx7rGAL5IiaNjCwrxoWVvnF3MTRuVm8bQE+ctU7QY2I33+KZgFtj+Ljb2H 79+LSubiiDyc3jn+3+pcDZ9V7HSXjFmuVacGGdFjMiJ78FjH+sjupuyTlUrNIZOh ASsoEKmDXGh/k8jqxI1BEFAkvJbfEabPsNuP+/+0lXEBn9aq+BA1e6APlZOsKCTS MQ0pX0SE5YUi45wCLRN34VwOaDRf9nYficawpVNML/aV5ryiB9oexaMBkb/g== 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=1716986654; x=1717073054; bh=JKuNXmKf0x8jkd+E4OJ5ht5rWpKY N4jbdROqCmu6FgI=; b=jPiohkZp8Sh+PvA3Crq9x+FiV5+d4QEemc09oVchDtRQ ILOP1/TPHm52y1jtBUZmqaxkHa1T3AERmu4cHhIiDCECCpwYRQxO0zSJ0SejY3ZZ J8AGRCw5X32h/0NuIOCErUQkQ4jnxnubRYY9b/QfTT54H4fGOU4A38Ig75WRDGhX 8H1Q2svrz958BK6SjRgPHO5y83Li5xjrOBXh0iIjtQayU3aXDmIhyX0OP35he7G6 V1/5akgeD1VEIy71ozf2O2UKzSrprNU1xBvPxbNVkR8Yg67V3E5l8+QSB4/WVfWk 4/OdXGwdImPFVT/qDLusX4FQ0ZYtB7H7bM/k88v1+w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:44:13 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 019d52fd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:43:59 +0000 (UTC) Date: Wed, 29 May 2024 14:44:11 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 02/19] global: assign non-const strings as required Message-ID: <51ee5660a1452797ac0a45819210141c57f3dcb9.1716983704.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: There are several cases where we initialize non-const fields with string constants. This is invalid and will cause warnings once we enable the `-Wwrite-strings` warning. Adapt those cases to instead use string arrays. Signed-off-by: Patrick Steinhardt --- builtin/remote.c | 3 ++- diff.c | 3 ++- entry.c | 7 ++++--- ident.c | 9 +++++++-- line-log.c | 3 ++- object-file.c | 3 ++- pretty.c | 5 +++-- refs/reftable-backend.c | 5 +++-- 8 files changed, 25 insertions(+), 13 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index d52b1c0e10..0324a5d48d 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -494,11 +494,12 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat struct ref *ref, *matches; struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map; struct refspec_item refspec; + char refspec_str[] = "refs/heads/*"; memset(&refspec, 0, sizeof(refspec)); refspec.force = 0; refspec.pattern = 1; - refspec.src = refspec.dst = "refs/heads/*"; + refspec.src = refspec.dst = refspec_str; get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0); matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"), fetch_map, 1); diff --git a/diff.c b/diff.c index ffd867ef6c..1439a5a01d 100644 --- a/diff.c +++ b/diff.c @@ -7231,11 +7231,12 @@ size_t fill_textconv(struct repository *r, struct diff_filespec *df, char **outbuf) { + static char empty_str[] = ""; size_t size; if (!driver) { if (!DIFF_FILE_VALID(df)) { - *outbuf = ""; + *outbuf = empty_str; return 0; } if (diff_populate_filespec(r, df, NULL)) diff --git a/entry.c b/entry.c index b8c257f6f9..2fc06ac90c 100644 --- a/entry.c +++ b/entry.c @@ -175,6 +175,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress) struct string_list_item *filter, *path; struct progress *progress = NULL; struct delayed_checkout *dco = state->delayed_checkout; + char empty_str[] = ""; if (!state->delayed_checkout) return errs; @@ -189,7 +190,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress) if (!async_query_available_blobs(filter->string, &available_paths)) { /* Filter reported an error */ errs = 1; - filter->string = ""; + filter->string = empty_str; continue; } if (available_paths.nr <= 0) { @@ -199,7 +200,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress) * filter from the list (see * "string_list_remove_empty_items" call below). */ - filter->string = ""; + filter->string = empty_str; continue; } @@ -225,7 +226,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress) * Do not ask the filter for available blobs, * again, as the filter is likely buggy. */ - filter->string = ""; + filter->string = empty_str; continue; } ce = index_file_exists(state->istate, path->string, diff --git a/ident.c b/ident.c index cc7afdbf81..df7aa42802 100644 --- a/ident.c +++ b/ident.c @@ -46,9 +46,14 @@ static struct passwd *xgetpwuid_self(int *is_bogus) pw = getpwuid(getuid()); if (!pw) { static struct passwd fallback; - fallback.pw_name = "unknown"; + static char fallback_name[] = "unknown"; #ifndef NO_GECOS_IN_PWENT - fallback.pw_gecos = "Unknown"; + static char fallback_gcos[] = "Unknown"; +#endif + + fallback.pw_name = fallback_name; +#ifndef NO_GECOS_IN_PWENT + fallback.pw_gecos = fallback_gcos; #endif pw = &fallback; if (is_bogus) diff --git a/line-log.c b/line-log.c index 8ff6ccb772..d9bf2c8120 100644 --- a/line-log.c +++ b/line-log.c @@ -1032,6 +1032,7 @@ static int process_diff_filepair(struct rev_info *rev, struct range_set tmp; struct diff_ranges diff; mmfile_t file_parent, file_target; + char empty_str[] = ""; assert(pair->two->path); while (rg) { @@ -1056,7 +1057,7 @@ static int process_diff_filepair(struct rev_info *rev, file_parent.ptr = pair->one->data; file_parent.size = pair->one->size; } else { - file_parent.ptr = ""; + file_parent.ptr = empty_str; file_parent.size = 0; } diff --git a/object-file.c b/object-file.c index 610b1f465c..c9e374e57e 100644 --- a/object-file.c +++ b/object-file.c @@ -282,12 +282,13 @@ static struct cached_object { } *cached_objects; static int cached_object_nr, cached_object_alloc; +static char empty_tree_buf[] = ""; static struct cached_object empty_tree = { .oid = { .hash = EMPTY_TREE_SHA1_BIN_LITERAL, }, .type = OBJ_TREE, - .buf = "", + .buf = empty_tree_buf, }; static struct cached_object *find_cached_object(const struct object_id *oid) diff --git a/pretty.c b/pretty.c index ec05db5655..1a0030b32a 100644 --- a/pretty.c +++ b/pretty.c @@ -1583,9 +1583,10 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ return 1; case 'D': { + char empty_str[] = ""; const struct decoration_options opts = { - .prefix = "", - .suffix = "" + .prefix = empty_str, + .suffix = empty_str, }; format_decorations(sb, commit, c->auto_color, &opts); diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 1af86bbdec..1908e74dea 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -1285,6 +1285,7 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data) struct strbuf errbuf = STRBUF_INIT; size_t logs_nr = 0, logs_alloc = 0, i; const char *committer_info; + char head[] = "HEAD"; int ret; committer_info = git_committer_info(0); @@ -1387,7 +1388,7 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data) if (append_head_reflog) { ALLOC_GROW(logs, logs_nr + 1, logs_alloc); logs[logs_nr] = logs[logs_nr - 1]; - logs[logs_nr].refname = "HEAD"; + logs[logs_nr].refname = head; logs_nr++; } } @@ -1463,7 +1464,7 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data) string_list_clear(&skip, 0); strbuf_release(&errbuf); for (i = 0; i < logs_nr; i++) { - if (!strcmp(logs[i].refname, "HEAD")) + if (logs[i].refname == head) continue; logs[i].refname = NULL; reftable_log_record_release(&logs[i]); From patchwork Wed May 29 12:44:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678790 Received: from wfhigh6-smtp.messagingengine.com (wfhigh6-smtp.messagingengine.com [64.147.123.157]) (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 AB788181325 for ; Wed, 29 May 2024 12:44:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986662; cv=none; b=pc0CoVTkxv+N3xSJEFmQmVvxlHV3fWbdXfXPM2hiyR4zTK2L1+qFIKi4PZ4jyjzE7righZ+vvT84v27O2EQUqtsnTjFoSGg6vCHDqy3QPtFwivWkY0RwXuVXMlPKb6KJ1vq8mm6tEXRNmX7OQUUDD0jQsF3s80rBbQoG0juBvV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986662; c=relaxed/simple; bh=ZmJCw0NZYB2EKYyw+OzTsspmciK1t1jx+274qxiTj3w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jtC9jGqKq9lwvXp+Bu6wU+bc5aL7iBPyQ1Yw4PwptX0Uf29l9k3yQWouad41u7/pcYuw6Q7OYzcYly0D/e9oY0fMztKi95nyyAqTjAphGZiI0HWbRPzxB6l2qaAmhZ0xC0dwPpB3yN1AJbeCCEwYeKS7Fn7xEaXLzjnxL+v3wCE= 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=jEAVJypN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XpjEdKs3; arc=none smtp.client-ip=64.147.123.157 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="jEAVJypN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XpjEdKs3" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id CB5511800122; Wed, 29 May 2024 08:44:19 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 29 May 2024 08:44:19 -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=1716986659; x=1717073059; bh=LSs4aIfKwp NSxYKPnn9sHrMj9L6Xy8EIanCRLK7q8LI=; b=jEAVJypNwAfFSHt9m1TBtixCNB RtUDIIt3KR9+y+OcJCq/pMglV6V9X7h6dUiyRcwhx7ADVwELjCYZyY5xnX9swhfA 5hdx9PkbXDjUXgX5aIFqsZtNDz24uz1SZWyAikki4QET+BnYUBeET+L5OgYzDqd2 RyarqlrmfW9Y3QaaaN5OqdIGHWjkkRGlAM3WZkjJqpf1VofUk0IFyYqxcavvGMAZ MfObjHL9B+2u2NxhxiLQJhXF1zP+qkk1nMnUdRlGYude6++KIay8DqlS/e5aobPe /gi5/S3Ud6RXwlps8+Cl/xks24WdOK9Ns91uoSeDDYcYeC/XMgj8/NhjmCdw== 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=1716986659; x=1717073059; bh=LSs4aIfKwpNSxYKPnn9sHrMj9L6X y8EIanCRLK7q8LI=; b=XpjEdKs3mq7bTblFJbx1QdIr/ZsBhujqOQJcMe7/c3bp Rt0OU6JnT+RfEyEZPYAH10cZfLXpg4f3M0/YvbAmR3waw10SKoYPxuULBUVkrJOy J1Tfp0NXVqxyNiPdkJ2QqY7tQaETBRpYfi6DvEt4szjA+lGGfF5dnO17r6pKgRlr fGayeGmC4Ms5RxRybD4/ZV8NMvcZny8vleX3LwyG9DG5yqfvjTTOEFOfZ+tM8g9m f4AG834XTzepq4+BcxlU0MUYXdDwq1iCPlMEnDjN8ZuktQayJe48vs27KfHsDXmd 7/AZ2Abl52GkCvQGBJ1jxIW+dqlwR4QUHy+MEFt3VQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:44:18 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id bb5cb10b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:44:04 +0000 (UTC) Date: Wed, 29 May 2024 14:44:16 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 03/19] global: convert intentionally-leaking config strings to consts Message-ID: <8f3decbb762916a536ec7a8d319c5903bd8f30c1.1716983704.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: There are multiple cases where we intentionally leak config strings: - `struct gpg_format` is used to track programs that can be used for signing commits, either via gpg(1), gpgsm(1) or ssh-keygen(1). The user can override the commands via several config variables. As the array is populated once, only, and will never be free'd, it is fine to treat the program as a quasi-constant. - `struct ll_merge_driver` is used to track merge drivers. Same as with the GPG format, these drivers are populated once and then reused. Its data is never free'd, either. - `struct userdiff_funcname` and `struct userdiff_driver` can be configured via `diff..*` to add additional drivers. Again, these have a global lifetime and are never free'd. All of these are intentionally kept alive and never free'd. Let's mark the respective fields as `const char *` and cast away the constness when assigning those values. Signed-off-by: Patrick Steinhardt --- gpg-interface.c | 4 ++-- merge-ll.c | 11 ++++++++--- userdiff.c | 10 +++++----- userdiff.h | 12 ++++++------ 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/gpg-interface.c b/gpg-interface.c index 71a9382a61..5c824aeb25 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -34,7 +34,7 @@ static enum signature_trust_level configured_min_trust_level = TRUST_UNDEFINED; struct gpg_format { const char *name; - char *program; + const char *program; const char **verify_args; const char **sigs; int (*verify_signed_buffer)(struct signature_check *sigc, @@ -783,7 +783,7 @@ static int git_gpg_config(const char *var, const char *value, if (fmtname) { fmt = get_format_by_name(fmtname); - return git_config_string(&fmt->program, var, value); + return git_config_string((char **) &fmt->program, var, value); } return 0; diff --git a/merge-ll.c b/merge-ll.c index e29b15fa4a..180c19df67 100644 --- a/merge-ll.c +++ b/merge-ll.c @@ -27,7 +27,7 @@ typedef enum ll_merge_result (*ll_merge_fn)(const struct ll_merge_driver *, struct ll_merge_driver { const char *name; - char *description; + const char *description; ll_merge_fn fn; char *recursive; struct ll_merge_driver *next; @@ -304,8 +304,13 @@ static int read_merge_config(const char *var, const char *value, ll_user_merge_tail = &(fn->next); } - if (!strcmp("name", key)) - return git_config_string(&fn->description, var, value); + if (!strcmp("name", key)) { + /* + * The description is leaking, but that's okay as we want to + * keep around the merge drivers anyway. + */ + return git_config_string((char **) &fn->description, var, value); + } if (!strcmp("driver", key)) { if (!value) diff --git a/userdiff.c b/userdiff.c index 82bc76b910..371032a413 100644 --- a/userdiff.c +++ b/userdiff.c @@ -399,7 +399,7 @@ static struct userdiff_driver *userdiff_find_by_namelen(const char *name, size_t static int parse_funcname(struct userdiff_funcname *f, const char *k, const char *v, int cflags) { - if (git_config_string(&f->pattern, k, v) < 0) + if (git_config_string((char **) &f->pattern, k, v) < 0) return -1; f->cflags = cflags; return 0; @@ -445,15 +445,15 @@ int userdiff_config(const char *k, const char *v) if (!strcmp(type, "binary")) return parse_tristate(&drv->binary, k, v); if (!strcmp(type, "command")) - return git_config_string(&drv->external, k, v); + return git_config_string((char **) &drv->external, k, v); if (!strcmp(type, "textconv")) - return git_config_string(&drv->textconv, k, v); + return git_config_string((char **) &drv->textconv, k, v); if (!strcmp(type, "cachetextconv")) return parse_bool(&drv->textconv_want_cache, k, v); if (!strcmp(type, "wordregex")) - return git_config_string(&drv->word_regex, k, v); + return git_config_string((char **) &drv->word_regex, k, v); if (!strcmp(type, "algorithm")) - return git_config_string(&drv->algorithm, k, v); + return git_config_string((char **) &drv->algorithm, k, v); return 0; } diff --git a/userdiff.h b/userdiff.h index cc8e5abfef..d726804c3e 100644 --- a/userdiff.h +++ b/userdiff.h @@ -7,19 +7,19 @@ struct index_state; struct repository; struct userdiff_funcname { - char *pattern; + const char *pattern; int cflags; }; struct userdiff_driver { const char *name; - char *external; - char *algorithm; + const char *external; + const char *algorithm; int binary; struct userdiff_funcname funcname; - char *word_regex; - char *word_regex_multi_byte; - char *textconv; + const char *word_regex; + const char *word_regex_multi_byte; + const char *textconv; struct notes_cache *textconv_cache; int textconv_want_cache; }; From patchwork Wed May 29 12:44:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678791 Received: from wfhigh6-smtp.messagingengine.com (wfhigh6-smtp.messagingengine.com [64.147.123.157]) (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 3D0F9142E68 for ; Wed, 29 May 2024 12:44:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986666; cv=none; b=SJvDQT+pE632kTvzOze6GedUyco2AyPIp1xdWcps6F9Jq4JoPoUfWrRQtKuVYUzOUJsH+E5OxAUFXP4h4OrzjpJfn5ks+zJJk8j1fztAKHrP09gXavEq9Buai19RLiqJYBBKSpyI10C+bOyWDrVB5xXpk7wv6t6vLDEtyO60tC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986666; c=relaxed/simple; bh=rKaIK9SF6RCjhLVg6wsjmclMnzbnCXo618tT75JsNgU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ff2fMSwmoNWodPkeiMAwXNXk2+5Zp1WNSwsRnrhV90XHbHmlesjKtDtU40Z8lQP3mDzRzSfuyNwBYucWineSdLy3Ifq7N0C03A737XIK9hv1jdSjbMQM+Jtpwl8yWr+rgLnnwbSaxgvVFSnXKNumw0FuXiaQaP561i/S1u0mSDY= 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=beEeazLD; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KW4xufu+; arc=none smtp.client-ip=64.147.123.157 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="beEeazLD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KW4xufu+" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.west.internal (Postfix) with ESMTP id 8A5201800121; Wed, 29 May 2024 08:44:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 29 May 2024 08:44:24 -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=1716986664; x=1717073064; bh=ARaraX1D0e NfY+Ts7uFPmDwPjhbjt3rSZWXSsuTb9ds=; b=beEeazLDIBG9JHB6yEi2iJhqdb vATNx1lsK2CU60ZcxnvaIGxvENfwRuoKLsKAWJi2t9uNN/+hOg/d+IyDhPmYcdgm raEcKd3fvPb4S9IQJWt0jUcBvNO7+dYqhNcE2AuJJ8VgdSuUxkBzSIb2ha0RY+TI 4JY6zaqxZ2mRX7UBGCtCDXCutdi0cnVEe4xlpffIJk2nvb6hRx5qSaRXLKYvLCKT ctGVWJBspZ7XReqKOn1tbbO0uWvMx27ZFYRHNIbECnE6TnSgsoKywrjBEhaYkIgx CI/EGrh2GsvjTxPFdE47gCHlEo5Emy5DQ0iLfqcTySOMXClg5/89Va/PaFrA== 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=1716986664; x=1717073064; bh=ARaraX1D0eNfY+Ts7uFPmDwPjhbj t3rSZWXSsuTb9ds=; b=KW4xufu+dEvBf1qvmwgtxbgV/6iik1VQCiMEHYCoF9Mn SPUnrLIsYPUKgmGdurJKik1UFciGgsDvjYd0pZsB9MrpbK6mKYlhnc1DrE9OGlT+ d0ahdQKI2//bjTuQGhksrubr6OYJmaeWqgFTcBGRYfsh3UHufGCCFYc2w3bjuTje MLhY9CS6FwzsdJdAzdVms4+Oeur98HLYd+LLeAZioCAXRumJlVen8GXy38sL5oBz ZqkCwokoson7fX6I3QTfTHvxV9SX2LNB7oL7owWUPts7oIxQKDlAYkVXbNZu6IyE XUF/Nhf6M8uL0Ju67mqx8cnyGfk3/727KvIWhA0GTA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:44:23 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 1ccf6f59 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:44:09 +0000 (UTC) Date: Wed, 29 May 2024 14:44:21 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 04/19] compat/win32: fix const-correctness with string constants 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: Adjust various places in our Win32 compatibility layer where we are not assigning string constants to `const char *` variables. Signed-off-by: Patrick Steinhardt --- compat/basename.c | 15 +++++++++++++-- compat/mingw.c | 25 +++++++++++++------------ compat/winansi.c | 2 +- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/compat/basename.c b/compat/basename.c index 96bd9533b4..c3c9d65fac 100644 --- a/compat/basename.c +++ b/compat/basename.c @@ -1,6 +1,13 @@ #include "../git-compat-util.h" #include "../strbuf.h" +/* + * Both basename(3P) and dirname(3P) are mis-specified because they return a + * non-constant pointer even though it is specified that they may return a + * pointer to internal memory. This variable here is a result of that. + */ +static char current_directory[] = "."; + /* Adapted from libiberty's basename.c. */ char *gitbasename (char *path) { @@ -10,7 +17,7 @@ char *gitbasename (char *path) skip_dos_drive_prefix(&path); if (!path || !*path) - return "."; + return current_directory; for (base = path; *path; path++) { if (!is_dir_sep(*path)) @@ -33,8 +40,12 @@ char *gitdirname(char *path) char *p = path, *slash = NULL, c; int dos_drive_prefix; + /* + * Same here, dirname(3P) is broken because it returns a non-constant + * pointer that may point to internal memory. + */ if (!p) - return "."; + return current_directory; if ((dos_drive_prefix = skip_dos_drive_prefix(&p)) && !*p) goto dot; diff --git a/compat/mingw.c b/compat/mingw.c index 6b06ea540f..60f0986f76 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -2257,6 +2257,7 @@ struct passwd *getpwuid(int uid) { static unsigned initialized; static char user_name[100]; + static char unknown[] = "unknown"; static struct passwd *p; wchar_t buf[100]; DWORD len; @@ -2279,7 +2280,7 @@ struct passwd *getpwuid(int uid) p->pw_name = user_name; p->pw_gecos = get_extended_user_info(NameDisplay); if (!p->pw_gecos) - p->pw_gecos = "unknown"; + p->pw_gecos = unknown; p->pw_dir = NULL; initialized = 1; @@ -2800,16 +2801,16 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report) strbuf_addf(report, "'%s' is on a file system that does " "not record ownership\n", path); } else if (report) { - LPSTR str1, str2, str3, str4, to_free1 = NULL, - to_free3 = NULL, to_local_free2 = NULL, - to_local_free4 = NULL; + PCSTR str1, str2, str3, str4; + LPSTR to_free1 = NULL, to_free3 = NULL, + to_local_free2 = NULL, to_local_free4 = NULL; - if (user_sid_to_user_name(sid, &str1)) - to_free1 = str1; + if (user_sid_to_user_name(sid, &to_free1)) + str1 = to_free1; else str1 = "(inconvertible)"; - if (ConvertSidToStringSidA(sid, &str2)) - to_local_free2 = str2; + if (ConvertSidToStringSidA(sid, &to_local_free2)) + str2 = to_local_free2; else str2 = "(inconvertible)"; @@ -2822,13 +2823,13 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report) str4 = "(invalid)"; } else { if (user_sid_to_user_name(current_user_sid, - &str3)) - to_free3 = str3; + &to_free3)) + str3 = to_free3; else str3 = "(inconvertible)"; if (ConvertSidToStringSidA(current_user_sid, - &str4)) - to_local_free4 = str4; + &to_local_free4)) + str4 = to_local_free4; else str4 = "(inconvertible)"; } diff --git a/compat/winansi.c b/compat/winansi.c index f83610f684..575813bde8 100644 --- a/compat/winansi.c +++ b/compat/winansi.c @@ -139,7 +139,7 @@ static void write_console(unsigned char *str, size_t len) /* convert utf-8 to utf-16 */ int wlen = xutftowcsn(wbuf, (char*) str, ARRAY_SIZE(wbuf), len); if (wlen < 0) { - wchar_t *err = L"[invalid]"; + const wchar_t *err = L"[invalid]"; WriteConsoleW(console, err, wcslen(err), &dummy, NULL); return; } From patchwork Wed May 29 12:44:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678792 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 3E6C2142E68 for ; Wed, 29 May 2024 12:44:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986672; cv=none; b=YVEccvnNma4h+f7dZib1MbKUjFfg+AAk1hxWoQCSkyjYT0NLvCnGc8tf6EE6A6/IHjMoVjFONCZ+XDFkhRJU4I/EPkb2C529pz7ixPMq4j42i3CgaG6dRNIIpBj1NvyYwF53TMQOf3pLc7YPVM42J3aYznCdpPvvMoicVtWQ7EE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986672; c=relaxed/simple; bh=D1Bvd2LSoY6v4CKxJubiT6ZoOo4sC04b7JcwBUuJzX0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tm3k3Qblg99xXFW/G4VkkEEdc19Mq5et4AnFq9Fa1KLgHCKMwS53f8BeoaH9n9rRZfGyeuBepT6vu7FeeC/4XTq/zbkq4vxWrFGklK+L9r0v9MGWdOZjNUEFLTz4m4pkk7/baip0AW81xH5SSf09UkAmKzjjlA9F5tUqTRszr04= 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=k5A0H15N; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MLSj7o+p; arc=none smtp.client-ip=64.147.123.147 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="k5A0H15N"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MLSj7o+p" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id 6140D1C0012D; Wed, 29 May 2024 08:44:29 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 29 May 2024 08:44:29 -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=1716986668; x=1717073068; bh=6AP1D/Ph8M ajefStJ5HPWtalGrWSVK1tqq2ggd2IMCM=; b=k5A0H15Naf5L85HMCT8PdkvJP3 dSjcFkh+S2W2ghW7XHCwppznidlCdbZ+Ziq3Ny/baVaHphTV6yq/mvReyPoSpBAw DRysq8O/fclNomHKOHx+M+qecprTWt53D1H9HYR262xf/FXxKivWv7Wcn994r2gX uj7qkaUzxbfdmWw6gsincyL8N3ZU/ypL+5VwsO/2PvFvY2WhCyZCBWVnggsBIQzh 6jeI4Qbsm/eOWRigaOjNvOJCjiG+2Ha3AKuk8RbiCe07aL5gohRYWasbeTBk2q/i HcOmxfF/OL9ZQsIJ+9wMEeWRozTgyIW1jfjXZoWYOF+Qpi9F8+p0KU+gje7Q== 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=1716986668; x=1717073068; bh=6AP1D/Ph8MajefStJ5HPWtalGrWS VK1tqq2ggd2IMCM=; b=MLSj7o+pHsic/7YEdrx7Wrk+whb0y4ZLgarokhswPFOU T3rzy4I7N03L2ora1GJhN3eGLxbxY65CmjKtfVFOJ9txelBEMLZbPGu8IRI83ftT Eb2/9N6cZqJfW+BOGNpy6LgLnYSW4C7q2L1ebtgRtpEoLpLnwu8dc1NinhamErEm ayLgYglozpTSWbcmraqkuC84CFjmFGQAG8dCKna2RHJV/luRzNFG4KEkpnTbBgkp j4sVNF5I8gqIW/ePvyn+zpgrW1wqP98fiEoJmB6mXWzEOfT9Mji2aqDU4xZzaX6b tnl5RSvNYYkcjtUTyQ9Pl/OvQyCOfa0s2YuZgNegWQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeegtddvkeegveejjeefgfdvffetfedvie dvleeuieelleffteegvdevvdejveekffenucffohhmrghinhepuhhpuggrthgvrdhnvgif pdhuphgurghtvgdrnhgrmhgvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:44:28 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 1f096dbd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:44:13 +0000 (UTC) Date: Wed, 29 May 2024 14:44:25 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 05/19] reftable: improve const correctness when assigning string constants 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: There are many cases in the reftable tests where we assign string constants to non-const fields. This is harmless because we know that those fields are only used for reading access, but will break once we enable `-Wwrite-strings`. Add explicit casts to prepare for this. Signed-off-by: Patrick Steinhardt --- reftable/basics_test.c | 4 +-- reftable/block_test.c | 2 +- reftable/merged_test.c | 45 +++++++++++++-------------- reftable/readwrite_test.c | 47 ++++++++++++++-------------- reftable/stack_test.c | 65 ++++++++++++++++++++------------------- 5 files changed, 82 insertions(+), 81 deletions(-) diff --git a/reftable/basics_test.c b/reftable/basics_test.c index 997c4d9e01..af9209d535 100644 --- a/reftable/basics_test.c +++ b/reftable/basics_test.c @@ -58,8 +58,8 @@ static void test_binsearch(void) static void test_names_length(void) { - char *a[] = { "a", "b", NULL }; - EXPECT(names_length(a) == 2); + char *names[] = { (char *)"a", (char *)"b", NULL }; + EXPECT(names_length(names) == 2); } static void test_parse_names_normal(void) diff --git a/reftable/block_test.c b/reftable/block_test.c index 26a9cfbc83..34c48c8091 100644 --- a/reftable/block_test.c +++ b/reftable/block_test.c @@ -42,7 +42,7 @@ static void test_block_read_write(void) block_writer_init(&bw, BLOCK_TYPE_REF, block.data, block_size, header_off, hash_size(GIT_SHA1_FORMAT_ID)); - rec.u.ref.refname = ""; + rec.u.ref.refname = (char *)""; rec.u.ref.value_type = REFTABLE_REF_DELETION; n = block_writer_add(&bw, &rec); EXPECT(n == REFTABLE_API_ERROR); diff --git a/reftable/merged_test.c b/reftable/merged_test.c index 530fc82d1c..6ab8ea2858 100644 --- a/reftable/merged_test.c +++ b/reftable/merged_test.c @@ -124,13 +124,13 @@ static void readers_destroy(struct reftable_reader **readers, size_t n) static void test_merged_between(void) { struct reftable_ref_record r1[] = { { - .refname = "b", + .refname = (char *)"b", .update_index = 1, .value_type = REFTABLE_REF_VAL1, .value.val1 = { 1, 2, 3, 0 }, } }; struct reftable_ref_record r2[] = { { - .refname = "a", + .refname = (char *)"a", .update_index = 2, .value_type = REFTABLE_REF_DELETION, } }; @@ -165,38 +165,38 @@ static void test_merged(void) { struct reftable_ref_record r1[] = { { - .refname = "a", + .refname = (char *)"a", .update_index = 1, .value_type = REFTABLE_REF_VAL1, .value.val1 = { 1 }, }, { - .refname = "b", + .refname = (char *)"b", .update_index = 1, .value_type = REFTABLE_REF_VAL1, .value.val1 = { 1 }, }, { - .refname = "c", + .refname = (char *)"c", .update_index = 1, .value_type = REFTABLE_REF_VAL1, .value.val1 = { 1 }, } }; struct reftable_ref_record r2[] = { { - .refname = "a", + .refname = (char *)"a", .update_index = 2, .value_type = REFTABLE_REF_DELETION, } }; struct reftable_ref_record r3[] = { { - .refname = "c", + .refname = (char *)"c", .update_index = 3, .value_type = REFTABLE_REF_VAL1, .value.val1 = { 2 }, }, { - .refname = "d", + .refname = (char *)"d", .update_index = 3, .value_type = REFTABLE_REF_VAL1, .value.val1 = { 1 }, @@ -291,46 +291,46 @@ static void test_merged_logs(void) { struct reftable_log_record r1[] = { { - .refname = "a", + .refname = (char *)"a", .update_index = 2, .value_type = REFTABLE_LOG_UPDATE, .value.update = { .old_hash = { 2 }, /* deletion */ - .name = "jane doe", - .email = "jane@invalid", - .message = "message2", + .name = (char *)"jane doe", + .email = (char *)"jane@invalid", + .message = (char *)"message2", } }, { - .refname = "a", + .refname = (char *)"a", .update_index = 1, .value_type = REFTABLE_LOG_UPDATE, .value.update = { .old_hash = { 1 }, .new_hash = { 2 }, - .name = "jane doe", - .email = "jane@invalid", - .message = "message1", + .name = (char *)"jane doe", + .email = (char *)"jane@invalid", + .message = (char *)"message1", } }, }; struct reftable_log_record r2[] = { { - .refname = "a", + .refname = (char *)"a", .update_index = 3, .value_type = REFTABLE_LOG_UPDATE, .value.update = { .new_hash = { 3 }, - .name = "jane doe", - .email = "jane@invalid", - .message = "message3", + .name = (char *)"jane doe", + .email = (char *)"jane@invalid", + .message = (char *)"message3", } }, }; struct reftable_log_record r3[] = { { - .refname = "a", + .refname = (char *)"a", .update_index = 2, .value_type = REFTABLE_LOG_DELETION, }, @@ -404,9 +404,8 @@ static void test_default_write_opts(void) struct strbuf buf = STRBUF_INIT; struct reftable_writer *w = reftable_new_writer(&strbuf_add_void, &noop_flush, &buf, &opts); - struct reftable_ref_record rec = { - .refname = "master", + .refname = (char *)"master", .update_index = 1, }; int err; diff --git a/reftable/readwrite_test.c b/reftable/readwrite_test.c index a6dbd214c5..72f66507ba 100644 --- a/reftable/readwrite_test.c +++ b/reftable/readwrite_test.c @@ -86,7 +86,7 @@ static void write_table(char ***names, struct strbuf *buf, int N, log.update_index = update_index; log.value_type = REFTABLE_LOG_UPDATE; set_test_hash(log.value.update.new_hash, i); - log.value.update.message = "message"; + log.value.update.message = (char *)"message"; n = reftable_writer_add_log(w, &log); EXPECT(n == 0); @@ -117,17 +117,18 @@ static void test_log_buffer_size(void) }; int err; int i; - struct reftable_log_record - log = { .refname = "refs/heads/master", - .update_index = 0xa, - .value_type = REFTABLE_LOG_UPDATE, - .value = { .update = { - .name = "Han-Wen Nienhuys", - .email = "hanwen@google.com", - .tz_offset = 100, - .time = 0x5e430672, - .message = "commit: 9\n", - } } }; + struct reftable_log_record log = { + .refname = (char *)"refs/heads/master", + .update_index = 0xa, + .value_type = REFTABLE_LOG_UPDATE, + .value.update = { + .name = (char *)"Han-Wen Nienhuys", + .email = (char *)"hanwen@google.com", + .tz_offset = 100, + .time = 0x5e430672, + .message = (char *)"commit: 9\n", + }, + }; struct reftable_writer *w = reftable_new_writer(&strbuf_add_void, &noop_flush, &buf, &opts); @@ -156,15 +157,15 @@ static void test_log_overflow(void) }; int err; struct reftable_log_record log = { - .refname = "refs/heads/master", + .refname = (char *)"refs/heads/master", .update_index = 0xa, .value_type = REFTABLE_LOG_UPDATE, .value = { .update = { .old_hash = { 1 }, .new_hash = { 2 }, - .name = "Han-Wen Nienhuys", - .email = "hanwen@google.com", + .name = (char *)"Han-Wen Nienhuys", + .email = (char *)"hanwen@google.com", .tz_offset = 100, .time = 0x5e430672, .message = msg, @@ -293,14 +294,14 @@ static void test_log_zlib_corruption(void) char message[100] = { 0 }; int err, i, n; struct reftable_log_record log = { - .refname = "refname", + .refname = (char *)"refname", .value_type = REFTABLE_LOG_UPDATE, .value = { .update = { .new_hash = { 1 }, .old_hash = { 2 }, - .name = "My Name", - .email = "myname@invalid", + .name = (char *)"My Name", + .email = (char *)"myname@invalid", .message = message, }, }, @@ -728,7 +729,7 @@ static void test_write_empty_key(void) struct reftable_writer *w = reftable_new_writer(&strbuf_add_void, &noop_flush, &buf, &opts); struct reftable_ref_record ref = { - .refname = "", + .refname = (char *)"", .update_index = 1, .value_type = REFTABLE_REF_DELETION, }; @@ -752,18 +753,18 @@ static void test_write_key_order(void) reftable_new_writer(&strbuf_add_void, &noop_flush, &buf, &opts); struct reftable_ref_record refs[2] = { { - .refname = "b", + .refname = (char *)"b", .update_index = 1, .value_type = REFTABLE_REF_SYMREF, .value = { - .symref = "target", + .symref = (char *)"target", }, }, { - .refname = "a", + .refname = (char *)"a", .update_index = 1, .value_type = REFTABLE_REF_SYMREF, .value = { - .symref = "target", + .symref = (char *)"target", }, } }; diff --git a/reftable/stack_test.c b/reftable/stack_test.c index 7889f818d1..0994f6bcda 100644 --- a/reftable/stack_test.c +++ b/reftable/stack_test.c @@ -83,7 +83,7 @@ static void test_read_file(void) char out[1024] = "line1\n\nline2\nline3"; int n, err; char **names = NULL; - char *want[] = { "line1", "line2", "line3" }; + const char *want[] = { "line1", "line2", "line3" }; int i = 0; EXPECT(fd > 0); @@ -116,13 +116,14 @@ static void test_parse_names(void) static void test_names_equal(void) { - char *a[] = { "a", "b", "c", NULL }; - char *b[] = { "a", "b", "d", NULL }; - char *c[] = { "a", "b", NULL }; - - EXPECT(names_equal(a, a)); - EXPECT(!names_equal(a, b)); - EXPECT(!names_equal(a, c)); + char a[] = "a", b[] = "b", c[] = "c", d[] = "d"; + char *abc[] = { a, b, c, NULL }; + char *abd[] = { a, b, d, NULL }; + char *ab[] = { a, b, NULL }; + + EXPECT(names_equal(abc, abc)); + EXPECT(!names_equal(abc, abd)); + EXPECT(!names_equal(abc, ab)); } static int write_test_ref(struct reftable_writer *wr, void *arg) @@ -156,10 +157,10 @@ static void test_reftable_stack_add_one(void) struct reftable_stack *st = NULL; int err; struct reftable_ref_record ref = { - .refname = "HEAD", + .refname = (char *)"HEAD", .update_index = 1, .value_type = REFTABLE_REF_SYMREF, - .value.symref = "master", + .value.symref = (char *)"master", }; struct reftable_ref_record dest = { NULL }; struct stat stat_result = { 0 }; @@ -216,16 +217,16 @@ static void test_reftable_stack_uptodate(void) int err; struct reftable_ref_record ref1 = { - .refname = "HEAD", + .refname = (char *)"HEAD", .update_index = 1, .value_type = REFTABLE_REF_SYMREF, - .value.symref = "master", + .value.symref = (char *)"master", }; struct reftable_ref_record ref2 = { - .refname = "branch2", + .refname = (char *)"branch2", .update_index = 2, .value_type = REFTABLE_REF_SYMREF, - .value.symref = "master", + .value.symref = (char *)"master", }; @@ -264,10 +265,10 @@ static void test_reftable_stack_transaction_api(void) struct reftable_addition *add = NULL; struct reftable_ref_record ref = { - .refname = "HEAD", + .refname = (char *)"HEAD", .update_index = 1, .value_type = REFTABLE_REF_SYMREF, - .value.symref = "master", + .value.symref = (char *)"master", }; struct reftable_ref_record dest = { NULL }; @@ -313,7 +314,7 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void) struct reftable_ref_record ref = { .update_index = reftable_stack_next_update_index(st), .value_type = REFTABLE_REF_SYMREF, - .value.symref = "master", + .value.symref = (char *)"master", }; char name[100]; @@ -356,7 +357,7 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void) static void test_reftable_stack_auto_compaction_fails_gracefully(void) { struct reftable_ref_record ref = { - .refname = "refs/heads/master", + .refname = (char *)"refs/heads/master", .update_index = 1, .value_type = REFTABLE_REF_VAL1, .value.val1 = {0x01}, @@ -409,16 +410,16 @@ static void test_reftable_stack_update_index_check(void) struct reftable_stack *st = NULL; int err; struct reftable_ref_record ref1 = { - .refname = "name1", + .refname = (char *)"name1", .update_index = 1, .value_type = REFTABLE_REF_SYMREF, - .value.symref = "master", + .value.symref = (char *)"master", }; struct reftable_ref_record ref2 = { - .refname = "name2", + .refname = (char *)"name2", .update_index = 1, .value_type = REFTABLE_REF_SYMREF, - .value.symref = "master", + .value.symref = (char *)"master", }; err = reftable_new_stack(&st, dir, cfg); @@ -561,7 +562,7 @@ static void test_reftable_stack_log_normalize(void) struct reftable_stack *st = NULL; char *dir = get_tmp_dir(__LINE__); struct reftable_log_record input = { - .refname = "branch", + .refname = (char *)"branch", .update_index = 1, .value_type = REFTABLE_LOG_UPDATE, .value = { @@ -582,11 +583,11 @@ static void test_reftable_stack_log_normalize(void) err = reftable_new_stack(&st, dir, cfg); EXPECT_ERR(err); - input.value.update.message = "one\ntwo"; + input.value.update.message = (char *)"one\ntwo"; err = reftable_stack_add(st, &write_test_log, &arg); EXPECT(err == REFTABLE_API_ERROR); - input.value.update.message = "one"; + input.value.update.message = (char *)"one"; err = reftable_stack_add(st, &write_test_log, &arg); EXPECT_ERR(err); @@ -594,7 +595,7 @@ static void test_reftable_stack_log_normalize(void) EXPECT_ERR(err); EXPECT(0 == strcmp(dest.value.update.message, "one\n")); - input.value.update.message = "two\n"; + input.value.update.message = (char *)"two\n"; arg.update_index = 2; err = reftable_stack_add(st, &write_test_log, &arg); EXPECT_ERR(err); @@ -697,9 +698,9 @@ static void test_reftable_stack_hash_id(void) int err; struct reftable_ref_record ref = { - .refname = "master", + .refname = (char *)"master", .value_type = REFTABLE_REF_SYMREF, - .value.symref = "target", + .value.symref = (char *)"target", .update_index = 1, }; struct reftable_write_options cfg32 = { .hash_id = GIT_SHA256_FORMAT_ID }; @@ -879,7 +880,7 @@ static void test_reftable_stack_auto_compaction(void) .refname = name, .update_index = reftable_stack_next_update_index(st), .value_type = REFTABLE_REF_SYMREF, - .value.symref = "master", + .value.symref = (char *)"master", }; snprintf(name, sizeof(name), "branch%04d", i); @@ -913,7 +914,7 @@ static void test_reftable_stack_add_performs_auto_compaction(void) struct reftable_ref_record ref = { .update_index = reftable_stack_next_update_index(st), .value_type = REFTABLE_REF_SYMREF, - .value.symref = "master", + .value.symref = (char *)"master", }; /* @@ -964,7 +965,7 @@ static void test_reftable_stack_compaction_concurrent(void) .refname = name, .update_index = reftable_stack_next_update_index(st1), .value_type = REFTABLE_REF_SYMREF, - .value.symref = "master", + .value.symref = (char *)"master", }; snprintf(name, sizeof(name), "branch%04d", i); @@ -1014,7 +1015,7 @@ static void test_reftable_stack_compaction_concurrent_clean(void) .refname = name, .update_index = reftable_stack_next_update_index(st1), .value_type = REFTABLE_REF_SYMREF, - .value.symref = "master", + .value.symref = (char *)"master", }; snprintf(name, sizeof(name), "branch%04d", i); From patchwork Wed May 29 12:44:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678793 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 DF366142E68 for ; Wed, 29 May 2024 12:44:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986676; cv=none; b=MAX/IPyeiay4P0Bxa+z7yKUz/Hk4ZYEu48QJA2h9Jtl3yaqCKPKA13Sa+/Quw+7ajPQGy67Pihvtio1iQoKoA2xLxKHaY7wwAEsE9cQo2FCyNAODoj3fjGHHAye+BOGOAuxfcI32N72JeGYIUjnjhuDhxTQvc/ASpUWbQb/CEvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986676; c=relaxed/simple; bh=YmVWCIFaSLTAvV/QiWxj8sJGnfJct3b5OGqw+BXQoY4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BLvQ7RmTmpLHPqglK+QqT8N+IfkhJW5zx/llCNt5hk/3uPykfM+dk/oDJl8siolyDhlrfvYCZoHdLi+xhU7qMCamSkp0FvDNV/iQzNtQcxS1GAo3cJLIfo1PLxOhk0NnDhIK4RThFqwBlhXWja2RaAhHd8bPkg/hxulOyVseZw0= 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=iyuRUt2U; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qcQlii1E; arc=none smtp.client-ip=64.147.123.147 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="iyuRUt2U"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qcQlii1E" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id 20D7D1C0012A; Wed, 29 May 2024 08:44:34 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 29 May 2024 08:44:34 -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=1716986673; x=1717073073; bh=nF00AtPZei D2DwHxgHD/ylPYerJzbwTT5k8ZRwiAnlQ=; b=iyuRUt2Ud1XiE4KKHfzvUqns3V SxuFJ58LUQKY2MEhYjMVkhnFsdFLXKbhIvUH63KsfOy6R+GVUsrUCvnJgXUUYbPd 4vDfeGgX9Q6mBi/tMftmmZ2LGVe8qRQMbrojdDSxCrS8G54oqBKxxS0g5t4Vw1nN nkTj4h3XBqPdvUA6AEOb4nhdsJ8YxHWO+gRJLrIB7PiJt1DMFABkPBCEQ327Q1gf fx9g3EZFAMniLSWELgrOTwWKoOGEw4YS7pQcRM4vPqJTsDeehBO1cTTTktNLRQKJ DYB+eSxQ2FyGqt6MuXD4PUf2nUZuI22G5gUkyXaPC3v3JazPnuE/w7IKIBGA== 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=1716986673; x=1717073073; bh=nF00AtPZeiD2DwHxgHD/ylPYerJz bwTT5k8ZRwiAnlQ=; b=qcQlii1EUoG+kGyHcibBSfFRYCz1QaY3mhCiL5fnPEtQ L2RaYL2FFRbkQjepjzDfONeOrYX3Fm1YnIIMmLDnw+ap6CEQZC0zHm/MrBQGZFh2 uVBGWFF0enGpaM3RrAd5m7U3OFaR7qkRGEq+OeBZertd/KM7MZMQHV6JtpuCI/Qc f+yHfF6rasEEca1vcdJGiQoz1zfvOyiurXwUNrJ45Y5caSs4q2mWQV4sPTcwZ/92 lfi7LNRp3xrWlHouAupqykBBj1f3XWeMkDxXXaBIDyxaQ2dzCERNYYNhGWtxvcaE RAZndCBJKWmA5ZCflKwnJlcB3k+uinWNeOLo8RcXdg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:44:32 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 9f47b0a0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:44:18 +0000 (UTC) Date: Wed, 29 May 2024 14:44:30 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 06/19] refspec: remove global tag refspec structure Message-ID: <0eaa73c109198b332e348921bc0a0dc49c687f98.1716983704.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: We have a global tag refspec structure that is used by both git-clone(1) and git-fetch(1). Initialization fo the structure will break once we enable `-Wwrite-strings`, even though the breakage is harmless. While we could just add casts, the structure isn't really required in the first place as we can simply initialize the structures at the respective callsites. Refactor the code accordingly. Signed-off-by: Patrick Steinhardt --- builtin/clone.c | 8 ++++++-- builtin/fetch.c | 11 ++++++++--- refspec.c | 13 ------------- refspec.h | 1 - 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index 92ab7d7165..bde1d284a2 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -523,6 +523,9 @@ static struct ref *wanted_peer_refs(const struct ref *refs, struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD")); struct ref *local_refs = head; struct ref **tail = head ? &head->next : &local_refs; + struct refspec_item tag_refspec; + + refspec_item_init(&tag_refspec, TAG_REFSPEC, 0); if (option_single_branch) { struct ref *remote_head = NULL; @@ -545,7 +548,7 @@ static struct ref *wanted_peer_refs(const struct ref *refs, &tail, 0); /* if --branch=tag, pull the requested tag explicitly */ - get_fetch_map(remote_head, tag_refspec, &tail, 0); + get_fetch_map(remote_head, &tag_refspec, &tail, 0); } free_refs(remote_head); } else { @@ -555,8 +558,9 @@ static struct ref *wanted_peer_refs(const struct ref *refs, } if (!option_mirror && !option_single_branch && !option_no_tags) - get_fetch_map(refs, tag_refspec, &tail, 0); + get_fetch_map(refs, &tag_refspec, &tail, 0); + refspec_item_clear(&tag_refspec); return local_refs; } diff --git a/builtin/fetch.c b/builtin/fetch.c index 75255dc600..06b60867f5 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -582,11 +582,16 @@ static struct ref *get_ref_map(struct remote *remote, } } - if (tags == TAGS_SET) + if (tags == TAGS_SET) { + struct refspec_item tag_refspec; + /* also fetch all tags */ - get_fetch_map(remote_refs, tag_refspec, &tail, 0); - else if (tags == TAGS_DEFAULT && *autotags) + refspec_item_init(&tag_refspec, TAG_REFSPEC, 0); + get_fetch_map(remote_refs, &tag_refspec, &tail, 0); + refspec_item_clear(&tag_refspec); + } else if (tags == TAGS_DEFAULT && *autotags) { find_non_local_tags(remote_refs, NULL, &ref_map, &tail); + } /* Now append any refs to be updated opportunistically: */ *tail = orefs; diff --git a/refspec.c b/refspec.c index d60932f4de..1df5de6c2f 100644 --- a/refspec.c +++ b/refspec.c @@ -7,19 +7,6 @@ #include "refspec.h" #include "strbuf.h" -static struct refspec_item s_tag_refspec = { - .force = 0, - .pattern = 1, - .matching = 0, - .exact_sha1 = 0, - .negative = 0, - .src = "refs/tags/*", - .dst = "refs/tags/*", -}; - -/* See TAG_REFSPEC for the string version */ -const struct refspec_item *tag_refspec = &s_tag_refspec; - /* * Parses the provided refspec 'refspec' and populates the refspec_item 'item'. * Returns 1 if successful and 0 if the refspec is invalid. diff --git a/refspec.h b/refspec.h index 8c0c446993..754be45cee 100644 --- a/refspec.h +++ b/refspec.h @@ -2,7 +2,6 @@ #define REFSPEC_H #define TAG_REFSPEC "refs/tags/*:refs/tags/*" -extern const struct refspec_item *tag_refspec; /** * A struct refspec_item holds the parsed interpretation of a refspec. If it From patchwork Wed May 29 12:44:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678794 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 AF208142E68 for ; Wed, 29 May 2024 12:44:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986681; cv=none; b=UNfl23KKdqIqBRdGPtBItJYKlrVcldk3xJ34CNQvgTgZWnA4kQ5IyqHqzvTwba95gb8IcD2VPwg4X0PAvoldheN02PgensuDgBP9xbFkGmMWXUVsgqKMt6kvuneJTqMTsbny/HsJJZp5BD3v0phWc3jAi6d0Yr/mD2G0JzCL2bE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986681; c=relaxed/simple; bh=wk9CV1AL5ubqpuhU6yIHqAK/CcLGDjIqHfYXRN6e7js=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SZjjd0zX51h08wqQdmGHOmUG7x7KRmvRVyUqg1mPvrbsnN/Iqvdm5wbR/8di4+gQaLFQ2hFztv6KaTvlhXloDhC6aJpHt2ZFZYKGb9G1SjFCnTaAPn44wUAoLVM94ZCWJf7UpeX4NVJbfa1YjgZsXFBQK44FO0imuSIt7PTuQrI= 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=c6HY8PRn; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=nm8z9f+K; arc=none smtp.client-ip=64.147.123.147 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="c6HY8PRn"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nm8z9f+K" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id DD94A1C00122; Wed, 29 May 2024 08:44:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 29 May 2024 08:44:39 -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=1716986678; x=1717073078; bh=hd/KBKn6AZ sB4vi2dTE0ZrSeMfGutRFzAZsjfvDfM78=; b=c6HY8PRn1m26fcxYqu2JJdHgn8 QPAASod8r0tmXQV3KMt4ivCe/NNNSze+F2t48o0xr6yH7jwRTBzWUV86zRUE1sA7 I5kzYUJEH3MOmYSAtv8sS0pGDepO1sL8EmRp6Mx23LZ0UQBnzyATRR5J1Le7Xp6F DRPHGAXadjvrTy9JnPAoTTtRTbr2fzzfuV19qnBsG7+MHr6XfJQEi5FIUh2Nin// RAYYP377W8/pxT5AyYkvezw18OJAyG9ot1nuShSs/lfB2EfyOLt0Az1HbwLzVTYo fihd1otG7Qk7sqp8Zlhei6+EeSUwYShxgID4c1nXfKDEv77P6fJGck/E5VXQ== 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=1716986678; x=1717073078; bh=hd/KBKn6AZsB4vi2dTE0ZrSeMfGu tRFzAZsjfvDfM78=; b=nm8z9f+KE8MehYEqrXy/uE7zZFtsrTISEqrPLqvvLWUU uxZMXHTs7ac0/H4uydn6mqFzEoKN5BbL5uCTxihniKMXxJ9SqAXEUPiCUbE7dTDi iL7WKpyZOgNaW3CArMtT/+GUvk5yYidT0luzl79cnhf58E0fO6bI08mMdhqZg4Pu YHSiHPU7JJ6j5OoHUr5uiaT7iRqxX8WwiB9OtQ4VVduzzeysCNPJfWuWn8xpMBhl fl4ptdByMgrdalGj1tAqvreA5EXRK/ffx+xGmYfW9SoRCXFKwLuycD6Ulofbhq8z RjOesWybBE6ADy0rw9XGvsl6ykUPLhtvqh7QTl0/hA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:44:37 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id c4089cc4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:44:23 +0000 (UTC) Date: Wed, 29 May 2024 14:44:35 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 07/19] http: do not assign string constant to non-const field Message-ID: <03b13c449b52ecfc845e8ffb0dd69fe67d50651c.1716983704.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: In `write_accept_language()`, we put all acceptable languages into an array. While all entries in that array are allocated strings, the final entry in that array is a string constant. This is fine because we explicitly skip over the last entry when freeing the array, but will cause warnings once we enable `-Wwrite-strings`. Adapt the code to also allocate the final entry. Signed-off-by: Patrick Steinhardt --- http.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/http.c b/http.c index 67cc47d28f..2dea2d03da 100644 --- a/http.c +++ b/http.c @@ -1974,7 +1974,7 @@ static void write_accept_language(struct strbuf *buf) /* add '*' */ REALLOC_ARRAY(language_tags, num_langs + 1); - language_tags[num_langs++] = "*"; /* it's OK; this won't be freed */ + language_tags[num_langs++] = xstrdup("*"); /* compute decimal_places */ for (max_q = 1, decimal_places = 0; @@ -2004,8 +2004,7 @@ static void write_accept_language(struct strbuf *buf) } } - /* free language tags -- last one is a static '*' */ - for (i = 0; i < num_langs - 1; i++) + for (i = 0; i < num_langs; i++) free(language_tags[i]); free(language_tags); } From patchwork Wed May 29 12:44:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678795 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 436FC142E68 for ; Wed, 29 May 2024 12:44:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986685; cv=none; b=uPKJFllnDbw76T4JkhrrNSo6zt15P2P7hWw1QO9IRzYxXiaDuTgsU7ICJM7DYf1ri2V8p70UvbMcX2ckDsnB0BQlKQMIWBE1JkRLk0u7GWwzPnqK3W50d5ZAUBGX9eGXrTODYs5sVeBY+jmMLHvpXsJ8FS5uxRvF3zUv/aFDXnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986685; c=relaxed/simple; bh=LWysdPrqul4FEP4uujm1303OdwEcW9zTO43kk4Bsma0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=s7BQilURQEMvHsDIGZsrf+jG3W4N9jpQqP7roEMrrSglMyQOxu2ORrEaWi8qNGHsZ6wB+GolYyGOQ89LABFYjkQUbiGI8UOCMuYOeSpt93bajDBDK6HuYJS6a0ZlSqxzTWzsKAoBsNFSGhcO0V8fHLRoBt+ukcEgZFLXPmmPG+c= 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=TZrI0dQ/; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Cg+jmoqk; arc=none smtp.client-ip=64.147.123.147 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="TZrI0dQ/"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Cg+jmoqk" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id B0DFE1C0012A; Wed, 29 May 2024 08:44:43 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 29 May 2024 08:44:43 -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=1716986683; x=1717073083; bh=LQCUNOKyiW 3UeoGMH2D0OfhNBNI+svjMOYkeJnQEQuA=; b=TZrI0dQ/OzRuyyLF+az4Kt/r2o WoaAsjb2GeLZEA52tGQdjBystkoAUOxadrXE/jAI69uWffPFKp+IggQIoexvAEnf lGlYQG/JxGdHnTEqCCIHkK3KpNrNxoAORhBUtfWA+aVOjak71YycwZ7FC26QLT+R mhORacrWyTxNNBuecEplxDwK/y92OGEjwEHItAXmpHJF9USaFZIVdzSIeIYgMxv9 E2TGmsGEEoMGLWMCvF9MICLBn3zJzy98fyNh6M4LnTG4mokbypPONApzVrT5Da6f YAheFBpCDTjbT8NVzWSzDiTFg0E0gX7a3b95WguOSwGisvLg8gLnAtZ7xzaQ== 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=1716986683; x=1717073083; bh=LQCUNOKyiW3UeoGMH2D0OfhNBNI+ svjMOYkeJnQEQuA=; b=Cg+jmoqkcPGcfHHDZEQfeGDWO2l+DT1c91nxFv9yqPDp vC9LCt+ZvfHFlaXVhGZf+8fmZShB22sCuZoDL28Ha0diAWTWngxLB0DxOn24oYlM X6XuBTCCma7V0jhERe/0Gh/A2gidJkIGCWlaDBCs4Sc5nuTpsA1k+q7P0elL8cZT 6o6YldZgqCICd1cN/7I2r/nHlxaXs8XPlvKWrfOStkjbe9LIi/Eu8XaPGEa+UFmB 7tAFV3VwJAnKuQJdEPu6rDV6mCQw5JWeKMvZHH/SL00euwGA8Yrvg/FWTUUwbNu2 mz+tzgXfy9/otQRdL+eC++wVUuum68ktRxriWH8fPg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:44:42 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 61639a25 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:44:27 +0000 (UTC) Date: Wed, 29 May 2024 14:44:39 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 08/19] line-log: always allocate the output prefix Message-ID: <699eeae92c0f58032fc76af68521d8cc60f12031.1716983704.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 returned string by `output_prefix()` is sometimes a string constant and sometimes an allocated string. This has been fine until now because we always leak the allocated strings, and thus we never tried to free the string constant. Fix the code to always return an allocated string and free the returned value at all callsites. Signed-off-by: Patrick Steinhardt --- line-log.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/line-log.c b/line-log.c index d9bf2c8120..9a298209d0 100644 --- a/line-log.c +++ b/line-log.c @@ -899,14 +899,12 @@ static void print_line(const char *prefix, char first, static char *output_prefix(struct diff_options *opt) { - char *prefix = ""; - if (opt->output_prefix) { struct strbuf *sb = opt->output_prefix(opt, opt->output_prefix_data); - prefix = sb->buf; + return sb->buf; + } else { + return xstrdup(""); } - - return prefix; } static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *range) @@ -927,7 +925,7 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang const char *c_context = diff_get_color(opt->use_color, DIFF_CONTEXT); if (!pair || !diff) - return; + goto out; if (pair->one->oid_valid) fill_line_ends(rev->diffopt.repo, pair->one, &p_lines, &p_ends); @@ -1002,8 +1000,10 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang c_context, c_reset, opt->file); } +out: free(p_ends); free(t_ends); + free(prefix); } /* @@ -1012,7 +1012,11 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang */ static void dump_diff_hacky(struct rev_info *rev, struct line_log_data *range) { - fprintf(rev->diffopt.file, "%s\n", output_prefix(&rev->diffopt)); + char *prefix = output_prefix(&rev->diffopt); + + fprintf(rev->diffopt.file, "%s\n", prefix); + free(prefix); + while (range) { dump_diff_hacky_one(rev, range); range = range->next; From patchwork Wed May 29 12:44:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678796 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 005BE142E68 for ; Wed, 29 May 2024 12:44:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986690; cv=none; b=OzKtTyf7cYjHHhkkutdc7Ut7QhLuQcebrBoTo81n0UAUcWngm6K2Mb67b4XgoWjfH5HFg8RGFtuAU/WbbkHJUwBnc7TbIRpRpCcFpVfcYQwNgkG4kcxC6L5mSTlOv0cF9SyXH4oKO4Sum5JmOA09LNpcXnF+CWZKv0aJUt/cIbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986690; c=relaxed/simple; bh=zD3uVtRVKftNRrYUSWHqnUgAUQSJ3+EUrtaVi980Kww=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TE6XIabS8nt3qa1ACi5YXtiurOKL+aCbaITY/KUxYpQh1b9k6BmebrFGgdSIPx//F1MzPUAh0+iy63sMmLDbxFdKZXEwFXpqu3WYC6Bv1r74oWsZKsOWeAqy6CqNKaT1/jliwszJRDGITZuWDcR1HX1pqyl3srGRybyZhaEPyrQ= 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=Astsbusf; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KY4M0n6r; arc=none smtp.client-ip=64.147.123.147 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="Astsbusf"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KY4M0n6r" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id 6F4B71C0012A; Wed, 29 May 2024 08:44:48 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 29 May 2024 08:44:48 -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=1716986688; x=1717073088; bh=PNPQngMdeF 0oy5oEzjKtPFtQNPtRZhC5gId+ecsdsb4=; b=AstsbusfafCG1R7JjWhrv2I+Uh 3G8qZqSYF5ikh/HYi6midY1WDc8UaVHh+L6hrsUiOepKs0mBOSJ7IArNwi+cmVTz xeN2Y1zumHmKLAy3IF3gfz7Zvewab09wh3PDnbD80RUGNdtBvoqwXmhfZInUA9Cl TpDz5Ns75S2m0C+GtjNbiY7L2gvnxYaqgnSqGdtazhPqLwtJ9jYm6b6XXvCfvvSu q4x+H2fRN7i4OfMAkZb8ZIK6jJk+1CU1hQ5YkyQs5OS92Og4ZQ3/ox5qCm9Ym04I b8Qxa/4+2v1k9WEwYvfAdrknzMfKa4Dt29pw/TJ1Xt/B2VwIXF3zC9DEXo7A== 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=1716986688; x=1717073088; bh=PNPQngMdeF0oy5oEzjKtPFtQNPtR ZhC5gId+ecsdsb4=; b=KY4M0n6r2gi7j6aYa2e97fw/jKg5YFwD/FNjD+gaDHdB YFBMjRBkwOx5j5bBUNWYVrTCq6mECiuwC1Cok4A9V0lrwUV29SqLF6rAe/VY8BaM pBHpAks+upi0ezRwJ4Ry6/qd8fEZpNHFCCeLWMZHMB2Y3VP2fJPAiiuXpJAaKhA8 EIMm1zW0hUrsAQqbpkoc4oHOqgIX3kwO9xG8A4zr/A/puQ73kuzvNaK4L75PXFpl yHR82B3xBZYHzpXgjwsOGKzmKzmCj4DZHHY56Vr/y04P3X/VseEEsl/Ms9GGQuG8 yddvX90n6M7pTWdG0aJFvdv4FD3iKXw3dxIcVar+3w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedvnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:44:47 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 3dc95511 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:44:32 +0000 (UTC) Date: Wed, 29 May 2024 14:44:44 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 09/19] object-file: make `buf` parameter of `index_mem()` a constant Message-ID: <6cbb8444a6dabb883ac3b0e450c0bfbd17b58bea.1716983704.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 `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; } From patchwork Wed May 29 12:44:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678797 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 C355B17DE23 for ; Wed, 29 May 2024 12:44:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986695; cv=none; b=VIp6xUqmPxSEhXxNh16pBlqml/boZ2pwgg72TVJ5E7RpAZkvFvHP2mAD+kco5Bt68crIXQxGrhNYL3C3FMHeKo9ZD7KE2V7WPY+kBE/z0OoVEV8rihLaww9Rb1HtVeq5+gl/0AJApWizdiQGNtTm9rmagqjgUiGJjpqPM/G0Ki4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986695; c=relaxed/simple; bh=2OLM8aCYa9H822q4x435RAx1HDHCHFMkxL8dAS1s9og=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kRX//PqJJnRMMxVzgD4DWxXKrd4ZmcAMRfkwD57erbMwlCNhOgB6K9NcXT/t5YwXMjHVIUZcxWjjNIJox1IZ9YTp48kkJD+0O0FdxilzKdHjVhyZzzXwc5MNV3D3wsGb1dt56Zdyuc3QVVy7ANIg3EoAL+QpBAJxh6zl1c6ocwE= 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=ku6xhrvu; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=nUs+BAAd; arc=none smtp.client-ip=64.147.123.147 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="ku6xhrvu"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nUs+BAAd" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id 3E3A81C0012A; Wed, 29 May 2024 08:44:53 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 29 May 2024 08:44:53 -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=1716986692; x=1717073092; bh=qiGltB2fm8 TXHjNSghWQAQaQrY9Uh1HE4fGM/kuIT30=; b=ku6xhrvuW2jHcVaZGQgeyPdlzw uWvvdO66iYuPkmZBiN0OWdDekjRpHR5jgyh0deHC3ENAcSexwPbtByFf3z7e4UrL v43IrEfj7aW20io1lxiparVoMTYz0k1GhYqY6Nwl8XSqUB3vT314AvUhqWeDms+0 pMqm67cZMF4x0xzHWvUhCbUie+93vqWy3RDZBRlH4TCVaNULAQHGycMCBwd1RdpO 46ygCVTmzCeI/o2hdCzGtMzaaQduY3N33/iOYMB6Bhvf+hjSogqVGXPvjhil1SLP UBOEYlv30CUwf+s1rIi98iY5ZzVFXHrAfalD2oxGULYrVVhv0nSRQUd+ol2w== 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=1716986692; x=1717073092; bh=qiGltB2fm8TXHjNSghWQAQaQrY9U h1HE4fGM/kuIT30=; b=nUs+BAAdRNqbfd5hS21OuU59/akQ82zPhundQ5AjAj/0 VqQYJ/mpZUPtDDkX6N3l42bzF8H4OosEL7GClXMofm2OkEblomodInRQuWc8P3lo Fj+mKM5KC6lElMzhsXSgwrZ+jqTyX0Xvj3p49IcUL7GdYnxASH5FFb2EE57xoGQs 9ioo+tnDeZOluOuI4S/ufvQHw9X8v/WZELN8CtDCCexavCipk6/2JHsVO21hgJav pkGuaQKVQOFnAUpC1FkDPsaSoFmfdE0uF9MxqbfZcVosasY8/fx1ApNPmLbvOIAB KsT75ZcHz0xxpJczNg1aVqs6vP1jsdG2yCD2YTWguA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedvnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:44:51 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 67372ce4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:44:37 +0000 (UTC) Date: Wed, 29 May 2024 14:44:49 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 10/19] parse-options: cast long name for OPTION_ALIAS 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: We assign the long name for OPTION_ALIAS options to a non-constant value field. We know that the variable will never be written to, but this will cause warnings once we enable `-Wwrite-strings`. Cast away the constness to be prepared for this change. Signed-off-by: Patrick Steinhardt --- parse-options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parse-options.h b/parse-options.h index bd62e20268..ae15342390 100644 --- a/parse-options.h +++ b/parse-options.h @@ -355,7 +355,7 @@ struct option { .type = OPTION_ALIAS, \ .short_name = (s), \ .long_name = (l), \ - .value = (source_long_name), \ + .value = (char *)(source_long_name), \ } #define OPT_SUBCOMMAND_F(l, v, fn, f) { \ From patchwork Wed May 29 12:44:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678798 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 98E1217DE23 for ; Wed, 29 May 2024 12:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986700; cv=none; b=V1xiN1qhOmeeI3aZFwBXvZ9cUtm7Byf8pzYW8YFU2VUQBZKhkEtziWkqQmPTCLiFzZGkUM9OqtiWfIUZBHWeusY0Kx+7wHUlUCPu0h2IXILJpC0z8X9x16HKnuCrVyvNDBAl8bJ8R/ZTPwUGYWl6jE2nKr9ij8jFPS0FcFgetsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986700; c=relaxed/simple; bh=n9ltBK6kA1YfefChF2RsndvU9ab2GJp4H6r4FJz3NMY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=muGGJiQ6ZiB52+xqUhtacCxUZP50VwxiddU9QVkRG0ni7dSQ68jqSrGR9VSgxpQL+ALfYIpnPtAdjofMSLnejYPbn7uazVvqnXE7YRKvogL8aa5L4lxB9ZqT6LdxDUxXQXb9SgNR2UkH8jL+aaVTxRBPxh70i8cK+k3M09uyheA= 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=izZpvhzr; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=dsA/Vi6K; arc=none smtp.client-ip=64.147.123.147 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="izZpvhzr"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="dsA/Vi6K" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id 120341C0012B; Wed, 29 May 2024 08:44:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 29 May 2024 08:44:58 -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=1716986697; x=1717073097; bh=QEWvrY7Ioh 5pxPYYIgtkwUPRFTUX+5AswJvln2Xlf1Q=; b=izZpvhzrHBIFSpnpt+pOrxf+Co W11pi1AsdOTn54W+HItBpsBY6Zn0F5UeQFg48JuDREScau4ii960TLkaK2wVerEd hg2TjLjjFg4/UMRC3CYnbUjHazA6S7ZQv7NMNyEkjwWnKSKU372ueRPtvg0dYeQx +61D4CGedna1L0EnnEyau77kOjVgVsLLd/azfzhNzTGiIkulRqtMRa7GD2ZdrDPG NTv3epk6UmFqbMQAaYGx1p3uxyc79epHNftjISEPrY3xzZMvLGeN4JZzZ/uA2q9K tndJoC/zdTzj2BG1wHhiL3oj0gEblPdoj4iTozBkP7yupsJA9+gUBNm67rMg== 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=1716986697; x=1717073097; bh=QEWvrY7Ioh5pxPYYIgtkwUPRFTUX +5AswJvln2Xlf1Q=; b=dsA/Vi6KzBb9zD7BFelXTMDctlEITvHbD39PhiFQP9UZ S2PYTy7cxgumb8HWWtq/9crTCpNvbk3AWKu4H9QkPgsQou3NCbYVYij8oQk+YNRR 16ZFOZ5QCQ1MbAYAn5lm4/qUl7Zo++0grrI15Jr42ENM+nzCfJStDIxbgbz7Z2Mt xn2hoOI8MzaPrc01zN7qF0JGoTKbyq3uCgvNrWscfMJsqu/r+H/TREVjgOJtaFZT 5uspDCA3sHVIUwEsG9KaTB8q2nu3OzxoWhbpz2ov6VSl9PGC43XXPIx10d7k0hhT ow4Vai2UKfpuSt8arTZJfK/4eqaQqnDY1Xbejox6vw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeefnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:44:56 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 1464fc60 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:44:42 +0000 (UTC) Date: Wed, 29 May 2024 14:44:54 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 11/19] send-pack: always allocate receive status Message-ID: <3cd28ae38c46e09607c06cc06868ad7692082d57.1716983704.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: In `receive_status()`, we record the reason why ref updates have been rejected by the remote via the `remote_status`. But while we allocate the assigned string when a reason was given, we assign a string constant when no reason was given. This has been working fine so far due to two reasons: - We don't ever free the refs in git-send-pack(1)' - Remotes always give a reason, at least as implemented by Git proper. Adapt the code to always allocate the receive status string and free the refs. Signed-off-by: Patrick Steinhardt --- builtin/send-pack.c | 2 ++ send-pack.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 3df9eaad09..17cae6bbbd 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -336,5 +336,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) /* stable plumbing output; do not modify or localize */ fprintf(stderr, "Everything up-to-date\n"); + free_refs(remote_refs); + free_refs(local_refs); return ret; } diff --git a/send-pack.c b/send-pack.c index 37f59d4f66..88e96d000b 100644 --- a/send-pack.c +++ b/send-pack.c @@ -259,7 +259,7 @@ static int receive_status(struct packet_reader *reader, struct ref *refs) if (p) hint->remote_status = xstrdup(p); else - hint->remote_status = "failed"; + hint->remote_status = xstrdup("failed"); } else { hint->status = REF_STATUS_OK; hint->remote_status = xstrdup_or_null(p); From patchwork Wed May 29 12:44:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678799 Received: from wfhigh6-smtp.messagingengine.com (wfhigh6-smtp.messagingengine.com [64.147.123.157]) (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 653394C70 for ; Wed, 29 May 2024 12:45:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986706; cv=none; b=XoO5SCMEDFZ7pkkZJwSLGGldTmbAVp/ryLQYRmzwrFQYGtcmwRFBZCLOxDNH+F4k4jRK+6Wbeg4kcfZl+TFl3QkcgPvQUZPMDI3vuNncWCLBtmYOkg+plQxfTfk8ju3u/Agq5OGZA+TRXrcMSh5LTJbHNBY5kljfUvoAW75YfVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986706; c=relaxed/simple; bh=RXoNTIdRxt4cPojTDi+FdBkjhPiYaryvLuloBAsel1k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f4ZeZb3a6jH5dF+UuxMn366Wh+AFn6psZIBALMIOK0j7olVyO6oul9YhTuNTfFPJu5bVlkg+M1RnSeyuB26Bvzs13imefjXT7joke8/558upOVelGewr4gt6SUeUIv6WfBDs+/NVq3gdq+UQS71x3qk9CTNweGhwu/u8TBjeQgc= 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=nCEYo6LN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MFRdWf3c; arc=none smtp.client-ip=64.147.123.157 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="nCEYo6LN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MFRdWf3c" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id C1F4C1800124; Wed, 29 May 2024 08:45:03 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 29 May 2024 08:45:03 -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=1716986703; x=1717073103; bh=wL8B1fD134 7cnd4vWot9bWq5ULmM/mQjkriYBfuZV9E=; b=nCEYo6LNM1anFitFjm2CkTv/5Y RbQfCEUl58aTg9p/1NVZrJzfBNn8xyxR+H+WBGFEdqERvU2WBvyXWjIhKFRlMFtR dgNgYf+Wgowrz4Ppdd63MwUjlu3JH6UHKZxP+ELRKvZLb/+SZAjrkwnAmZjtQVts WHGf/UTm1AQ+hP65WOBjgqt/ZOs+DRS4K8kYb8xX4B8BcmIey/+q593hIuGpvH7v kQLymWwKqYnkTVlHWcR5WgK2t5Ba1OmkhPYPCkpCPg/JioK40gXz7Iw0Cleu56zr dfQelgQeVAQH7G4VbQRx8wduMX9b4ypChU5EeP/UqhOihvOtGrbi5plEgBEQ== 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=1716986703; x=1717073103; bh=wL8B1fD1347cnd4vWot9bWq5ULmM /mQjkriYBfuZV9E=; b=MFRdWf3c0aI92MLbxOqug5WTdaCmxMuklCsTw34In3Y5 /hXmtBCxBmgm0BEJN2C1Fj5sMILpI7BWTafWV/CqDH/j4B/eE/qJDyb9aLmLzjXG txozk2EJNSmYspPbMCgTJKs5bFvbWEgeS/SxYjQ0WBZ8HC1B5tnrdT0vASTOOacj SibOb6u0ssRcsNHdLrZZuHWYd+1mZ/p5jgFbcntQO+KriSzx2y2R6i3YrRw/i6eo EtFnPdYqmVyVFDiaCMlGoNGWesihAdOjB4jAESMC0FcPgIu8GIodXfu0MnTv2hYk Yz4Xx7zJVGMO2KEiJmTk9Ib2S3jXo+umA51574doUA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeegnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:45:02 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 01c0a0c9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:44:47 +0000 (UTC) Date: Wed, 29 May 2024 14:44:59 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 12/19] remote-curl: avoid assigning string constant to non-const variable Message-ID: <00b4a7dbbcdfd8a0f7b4beb4ecaf272257838460.1716983704.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: When processing remote options, we split the option line into two by searching for a space. If there is one, we replace the space with '\0', otherwise we implicitly assume that the value is "true" and thus assign a string constant. As the return value of strchr(3P) weirdly enough is a `char *` even though it gets a `const char *` as input, the assigned-to variable also is a non-constant. This is fine though because the argument is in fact an allocated string, and thus we are allowed to modify it. But this will break once we enable `-Wwrite-strings`. Refactor the code stop splitting the fields with '\0' altogether. Instead, we can pass the length of the option name to `set_option()` and then use strncmp(3P) instead of strcmp(3P). Signed-off-by: Patrick Steinhardt --- remote-curl.c | 58 +++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/remote-curl.c b/remote-curl.c index cae98384da..ac185d4f88 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -58,9 +58,9 @@ struct options { static struct options options; static struct string_list cas_options = STRING_LIST_INIT_DUP; -static int set_option(const char *name, const char *value) +static int set_option(const char *name, size_t namelen, const char *value) { - if (!strcmp(name, "verbosity")) { + if (!strncmp(name, "verbosity", namelen)) { char *end; int v = strtol(value, &end, 10); if (value == end || *end) @@ -68,7 +68,7 @@ static int set_option(const char *name, const char *value) options.verbosity = v; return 0; } - else if (!strcmp(name, "progress")) { + else if (!strncmp(name, "progress", namelen)) { if (!strcmp(value, "true")) options.progress = 1; else if (!strcmp(value, "false")) @@ -77,7 +77,7 @@ static int set_option(const char *name, const char *value) return -1; return 0; } - else if (!strcmp(name, "depth")) { + else if (!strncmp(name, "depth", namelen)) { char *end; unsigned long v = strtoul(value, &end, 10); if (value == end || *end) @@ -85,15 +85,15 @@ static int set_option(const char *name, const char *value) options.depth = v; return 0; } - else if (!strcmp(name, "deepen-since")) { + else if (!strncmp(name, "deepen-since", namelen)) { options.deepen_since = xstrdup(value); return 0; } - else if (!strcmp(name, "deepen-not")) { + else if (!strncmp(name, "deepen-not", namelen)) { string_list_append(&options.deepen_not, value); return 0; } - else if (!strcmp(name, "deepen-relative")) { + else if (!strncmp(name, "deepen-relative", namelen)) { if (!strcmp(value, "true")) options.deepen_relative = 1; else if (!strcmp(value, "false")) @@ -102,7 +102,7 @@ static int set_option(const char *name, const char *value) return -1; return 0; } - else if (!strcmp(name, "followtags")) { + else if (!strncmp(name, "followtags", namelen)) { if (!strcmp(value, "true")) options.followtags = 1; else if (!strcmp(value, "false")) @@ -111,7 +111,7 @@ static int set_option(const char *name, const char *value) return -1; return 0; } - else if (!strcmp(name, "dry-run")) { + else if (!strncmp(name, "dry-run", namelen)) { if (!strcmp(value, "true")) options.dry_run = 1; else if (!strcmp(value, "false")) @@ -120,7 +120,7 @@ static int set_option(const char *name, const char *value) return -1; return 0; } - else if (!strcmp(name, "check-connectivity")) { + else if (!strncmp(name, "check-connectivity", namelen)) { if (!strcmp(value, "true")) options.check_self_contained_and_connected = 1; else if (!strcmp(value, "false")) @@ -129,7 +129,7 @@ static int set_option(const char *name, const char *value) return -1; return 0; } - else if (!strcmp(name, "cas")) { + else if (!strncmp(name, "cas", namelen)) { struct strbuf val = STRBUF_INIT; strbuf_addstr(&val, "--force-with-lease="); if (*value != '"') @@ -139,7 +139,7 @@ static int set_option(const char *name, const char *value) string_list_append(&cas_options, val.buf); strbuf_release(&val); return 0; - } else if (!strcmp(name, TRANS_OPT_FORCE_IF_INCLUDES)) { + } else if (!strncmp(name, TRANS_OPT_FORCE_IF_INCLUDES, namelen)) { if (!strcmp(value, "true")) options.force_if_includes = 1; else if (!strcmp(value, "false")) @@ -147,7 +147,7 @@ static int set_option(const char *name, const char *value) else return -1; return 0; - } else if (!strcmp(name, "cloning")) { + } else if (!strncmp(name, "cloning", namelen)) { if (!strcmp(value, "true")) options.cloning = 1; else if (!strcmp(value, "false")) @@ -155,7 +155,7 @@ static int set_option(const char *name, const char *value) else return -1; return 0; - } else if (!strcmp(name, "update-shallow")) { + } else if (!strncmp(name, "update-shallow", namelen)) { if (!strcmp(value, "true")) options.update_shallow = 1; else if (!strcmp(value, "false")) @@ -163,7 +163,7 @@ static int set_option(const char *name, const char *value) else return -1; return 0; - } else if (!strcmp(name, "pushcert")) { + } else if (!strncmp(name, "pushcert", namelen)) { if (!strcmp(value, "true")) options.push_cert = SEND_PACK_PUSH_CERT_ALWAYS; else if (!strcmp(value, "false")) @@ -173,7 +173,7 @@ static int set_option(const char *name, const char *value) else return -1; return 0; - } else if (!strcmp(name, "atomic")) { + } else if (!strncmp(name, "atomic", namelen)) { if (!strcmp(value, "true")) options.atomic = 1; else if (!strcmp(value, "false")) @@ -181,7 +181,7 @@ static int set_option(const char *name, const char *value) else return -1; return 0; - } else if (!strcmp(name, "push-option")) { + } else if (!strncmp(name, "push-option", namelen)) { if (*value != '"') string_list_append(&options.push_options, value); else { @@ -192,7 +192,7 @@ static int set_option(const char *name, const char *value) strbuf_detach(&unquoted, NULL)); } return 0; - } else if (!strcmp(name, "family")) { + } else if (!strncmp(name, "family", namelen)) { if (!strcmp(value, "ipv4")) git_curl_ipresolve = CURL_IPRESOLVE_V4; else if (!strcmp(value, "ipv6")) @@ -202,16 +202,16 @@ static int set_option(const char *name, const char *value) else return -1; return 0; - } else if (!strcmp(name, "from-promisor")) { + } else if (!strncmp(name, "from-promisor", namelen)) { options.from_promisor = 1; return 0; - } else if (!strcmp(name, "refetch")) { + } else if (!strncmp(name, "refetch", namelen)) { options.refetch = 1; return 0; - } else if (!strcmp(name, "filter")) { + } else if (!strncmp(name, "filter", namelen)) { options.filter = xstrdup(value); return 0; - } else if (!strcmp(name, "object-format")) { + } else if (!strncmp(name, "object-format", namelen)) { options.object_format = 1; if (strcmp(value, "true")) die(_("unknown value for object-format: %s"), value); @@ -1588,15 +1588,19 @@ int cmd_main(int argc, const char **argv) parse_push(&buf); } else if (skip_prefix(buf.buf, "option ", &arg)) { - char *value = strchr(arg, ' '); + const char *value = strchr(arg, ' '); + size_t arglen; int result; - if (value) - *value++ = '\0'; - else + if (value) { + arglen = value - arg; + value++; + } else { + arglen = strlen(arg); value = "true"; + } - result = set_option(arg, value); + result = set_option(arg, arglen, value); if (!result) printf("ok\n"); else if (result < 0) From patchwork Wed May 29 12:45:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678800 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 157ED4C70 for ; Wed, 29 May 2024 12:45:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986710; cv=none; b=d5nEYCHaahfScP5LEr7XCpppjoaQ5s8lYQ7ikuB10SUaVfvrL96HYNeVxb96jGpuyx4s/LfSHTu6wid9oa2ZY4WUj6paYZtqbKDeHMzLZ44UjeLvS5M4eHL6sWhTPsZugH8XGKpLSvZMbj+fH10ZLLbC2cVIplEC81MnigB8Pyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986710; c=relaxed/simple; bh=CjYT7DSaBFC1tJIOFf4qc5KYMyG7XXDpMMctdL7lJKE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kb4q7MytiXyR5TgLUB9rKmM/N6kyw/cmDiiNcs5w1vQR80Qgi5xNF8ZbTfkn6O5Tg+Tm2O/brcgeO3eTYvQV3Ddci6a4flAeR5LGkRgA4HM1xOFhxW4BNA3e019/8uml586u1lgBt4xgCswRvm7qs3PiMJwvTQGtfpUvbzZT2iA= 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=D8Lhw6Ie; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=blgytz0h; arc=none smtp.client-ip=64.147.123.147 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="D8Lhw6Ie"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="blgytz0h" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 802F51C00111; Wed, 29 May 2024 08:45:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 29 May 2024 08:45:08 -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=1716986708; x=1717073108; bh=05lJR+/xSF 8qj52MRptMuBQ6L5ekr/o6aEwo96BjKdA=; b=D8Lhw6IeJxOHcei2NYqJ62l4JH GxKm7dlMsNEqolJ8sC8vvvIEQZsanAZOlVQEuUzRukLAH8beFzxk/5uLOujEEK9q wFA75doQtNdm8oj2GX97F/VzxQG3wdDUg6azyax1H7Y3SknJ9V9HfNLQ9ondeOVg 6hx1xKE75C+YHZFYuBcYUmsGAS+zeRjqp7R3C1raT4hKnw2yqO7Sjt1G9cc/sAgW NyepamQLCDp/lfmcM7RgEKENaN9/3dEHM28snhAUcN6nwB5msPKw/+4eAKLabpim p5Wngf5wa22vkccAjvZ+vWF/dW+PKFdEBWxz8pNsLzl9JQlIeac0X0rNMJgQ== 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=1716986708; x=1717073108; bh=05lJR+/xSF8qj52MRptMuBQ6L5ek r/o6aEwo96BjKdA=; b=blgytz0hJYk+jt45+UP/DLD/7QVPX1me41yOGSLiOQEF fSSqWRzhtGKsUCLutFyrH+9AzGEZaYhdCfSGyjsJH48gkHMZ7WmF343AzgAOEyev HB7V3gdjdpmDzKsTelh9i2caziuY97lErDBuVnV4/2rdkMspIQjuTs6defnos7vg nFwwOCj/tsgTwgPzfKeycrGumGw+Sea9977mWkewehCX7zdLPzoEFrL0rRX5zT/2 Y3K49axQ19RJX7Wt1t43Y5q38eSGTiHh5NQUIhH4id7MZEqaZoWyBeAzojNvsDsv jy5NaF7km3827FS+yqQQsLp9lVE292CDhcqcxLeXeg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedvnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:45:07 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 5eb3e4c5 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:44:52 +0000 (UTC) Date: Wed, 29 May 2024 14:45:04 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 13/19] revision: always store allocated strings in output encoding Message-ID: <68a7d24e4a715eaf60414373636860215d27e643.1716983704.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 `git_log_output_encoding` variable can be set via the `--encoding=` option. When doing so, we conditionally either assign it to the passed value, or if the value is "none" we assign it the empty string. Depending on which of the both code paths we pick though, the variable may end up being assigned either an allocated string or a string constant. This is somewhat risky and may easily lead to bugs when a different code path may want to reassign a new value to it, freeing the previous value. We already to this when parsing the "i18n.logoutputencoding" config in `git_default_i18n_config()`. But because the config is typically parsed before we parse command line options this has been fine so far. Regardless of that, safeguard the code such that the variable always contains an allocated string. While at it, also free the old value in case there was any to plug a potential memory leak. Signed-off-by: Patrick Steinhardt --- revision.c | 3 ++- t/t3900-i18n-commit.sh | 1 + t/t3901-i18n-patch.sh | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/revision.c b/revision.c index 7ddf0f151a..2ee6886078 100644 --- a/revision.c +++ b/revision.c @@ -2650,10 +2650,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg } else if (!strcmp(arg, "--invert-grep")) { revs->grep_filter.no_body_match = 1; } else if ((argcount = parse_long_opt("encoding", argv, &optarg))) { + free(git_log_output_encoding); if (strcmp(optarg, "none")) git_log_output_encoding = xstrdup(optarg); else - git_log_output_encoding = ""; + git_log_output_encoding = xstrdup(""); return argcount; } else if (!strcmp(arg, "--reverse")) { revs->reverse ^= 1; diff --git a/t/t3900-i18n-commit.sh b/t/t3900-i18n-commit.sh index f27d09cfd9..db7b403bc1 100755 --- a/t/t3900-i18n-commit.sh +++ b/t/t3900-i18n-commit.sh @@ -5,6 +5,7 @@ test_description='commit and log output encodings' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh compare_with () { diff --git a/t/t3901-i18n-patch.sh b/t/t3901-i18n-patch.sh index 4b37f78829..5f0b9afc3f 100755 --- a/t/t3901-i18n-patch.sh +++ b/t/t3901-i18n-patch.sh @@ -8,6 +8,7 @@ test_description='i18n settings and format-patch | am pipe' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh check_encoding () { From patchwork Wed May 29 12:45:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678801 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 0453D4C70 for ; Wed, 29 May 2024 12:45:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986715; cv=none; b=k2MG7Uz9DcKMDo6jI5RU/zatwbkscox6/ojaW/+jah7NK7I2brm2mkBS1ohyP2EqhKmpABuDXjGDFer3eu/a4ksApOCAq5W/vTqXgBLVbST68HlqqK6ucPXP3WUP0wJz24UtpYs8DVtZSX01GPIDIZ0nD7bu4qs4To6E3eO6XpM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986715; c=relaxed/simple; bh=mooNOdW8hzdm+jm2Z2ntufcUxqvWvPYR/7mSwjnKfP8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Yu7Lt5kMLsnj1QRyw+bPgkRRpKcY8EYQ64ZKN84hxzNZm3AtQzNpFNWZHZDlucRlap8nkHK88btYny2hXh4Rhr3OFve84Tc5GmbIJZAslxwRXBjL1Va5Qr+y5/AZWsdApBrK69XdIuA0lm1porGlPfSYkI0A/qzesjtU+PavhsI= 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=iss3F0qV; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XjkZYcpF; arc=none smtp.client-ip=64.147.123.147 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="iss3F0qV"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XjkZYcpF" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id 55C031C000BF; Wed, 29 May 2024 08:45:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 29 May 2024 08:45:13 -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=1716986712; x=1717073112; bh=Ur8bXUargy EXX3WA/QlCkr1k6V29ZzNUiRdU2z6ZtRg=; b=iss3F0qVoCmhjO8Ql28tFyb7Mu MIdvsDupfLw56JmBvTrIskzCJnU3HDWMdJ3miOjQ4DjSjuYpP4V/hqY/xJ1u48Va KKvhgGNotaww7Sa2wkGQHbe9qy93yWxA0LRMDO0xC64BVHoZRdqJhiahBXzQyVld x2DAQYrbbjkRrquFRvxYnxFhRznxflQmh49T3mgfc42GExjECJDuvbZ+m519XYOT hY5m4K5nT8HQSE2Fq/Ffpy2CvGiduAVZcYKGBPgrFDvLuU7sJpt8YwPvCT7i7UAA Mf3MvTNy26pQBfLkpa4EVACGdhWzrCtr2LajyOJkmw49gQPMJYKg448Oih1w== 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=1716986712; x=1717073112; bh=Ur8bXUargyEXX3WA/QlCkr1k6V29 ZzNUiRdU2z6ZtRg=; b=XjkZYcpF2XaB8yJtO+e5HvvDYtKehgUK9j+NGVh6QAa/ 8OGpmJgb4cKLwOeum9pFerEPAh1tzBjJWY0nOcEsJyERgBmDyETlN38QxSFhQzHi +1F1ZNJeHsE6g8AZyhGOnanD/Ys20N9YRumnYQQqz+RWePjZa9tVsg7CERyZEAwn bIaxgkEthMQMPL91kWKEOrOPFLM6YhSO4gk4Pl6dnnrO7BbLiYck95mJCZOmFB5Z Wj3d7A90j1W4FhZMqkIDOLZ76ZHJHTDGPwEggxFp++V1T/f2QT/tNkpJZMOsgITn WTsJfM2hZ3PJegSIHl/mxnnGN3evgq+J12UnCFsVlQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:45:11 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 3b8e7c06 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:44:57 +0000 (UTC) Date: Wed, 29 May 2024 14:45:09 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 14/19] mailmap: always store allocated strings in mailmap blob Message-ID: <0e393fa6a708fc29fe666b75d89ed66cc69ec634.1716983704.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: Same as with the preceding commit, the `git_mailmap_blob` may sometimes contain an allocated string and sometimes it may contain a string constant. This is risky and can easily lead to bugs in case the variable is getting re-assigned, where the code may then try to free the previous value to avoid memory leaks. Safeguard the code by always storing allocated strings in the variable. Signed-off-by: Patrick Steinhardt --- mailmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailmap.c b/mailmap.c index b2efe29b3d..3d1e092fef 100644 --- a/mailmap.c +++ b/mailmap.c @@ -216,7 +216,7 @@ int read_mailmap(struct string_list *map) map->cmp = namemap_cmp; if (!git_mailmap_blob && is_bare_repository()) - git_mailmap_blob = "HEAD:.mailmap"; + git_mailmap_blob = xstrdup("HEAD:.mailmap"); if (!startup_info->have_repository || !is_bare_repository()) err |= read_mailmap_file(map, ".mailmap", From patchwork Wed May 29 12:45:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678802 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 95E874C70 for ; Wed, 29 May 2024 12:45:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986720; cv=none; b=ktuH0HaO5l0V6hONHOzmhuIcfMnmMTHtnNUz4TdnUbfnobqwA3FZoI04EQNCTyCcTZtjlIvl1l9NbvvVrWhkNLvldkwUckEIc8b+mOHzYgJo8A/awx3cVioIyj9Wap4S7Vta4v6drUvfJ/GaLRWJRHFCHCIG8W0JNOs9M0tF+bY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986720; c=relaxed/simple; bh=yMumKXk/UvZpXz+A+LcERMwzVkI5eSHIJQBazCgQzTY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CQLNS1VuV/1yNDy/ybAHZnfihmC5QQYaNnjc+BrD7c0AA9DgE1LsuyxyZregaazaemhtT8ZQUkNZ293LKFwXQoV5LiB8E/y/ETwVbQG0UuLImlKEDas2NMsju/6KyvnDhW8TPkukCdW3bc+H5okpu65ZZ4FyraSrnwbk7mhZWM8= 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=ZVY+Oyz7; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qDJqECmK; arc=none smtp.client-ip=64.147.123.147 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="ZVY+Oyz7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qDJqECmK" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id 064861C000BF; Wed, 29 May 2024 08:45:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 29 May 2024 08:45:18 -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=1716986717; x=1717073117; bh=E1ftiiaA7S v4BodpfQLInScoIauCgc6S7a0gP8Fbu4g=; b=ZVY+Oyz7tJHxXRY3WbiCj9iaQs oLnG3UwroFolTT9cm4N9XV7AzOjm8kwMleJxmHh3Zbun7qy6AUGsJDP80C3b1qMI hh/e9sy2/f9hx6p/6zYDLWRcfQjMxCMLTWYuw86ZjMy6eHQVaCLSMxzfJla5iWh1 wdVbx7JeB4cfx+nUSz3els2ZUkz/TTAJtjfUkNwHygdNYAxGn3G2eNJYSBjhKUWp HOKq+JE2OOnGLjstOPBCLaLhHvw/whEe9cHmj/l5BFSER/7UmfW1eMRwpU4gPPN2 nTHG46jVBu3GTlYnQ8X4pt9eWHFpJGe+mgfRx6nASYKAfIY7gVPlSr8EW1Tg== 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=1716986717; x=1717073117; bh=E1ftiiaA7Sv4BodpfQLInScoIauC gc6S7a0gP8Fbu4g=; b=qDJqECmKaU1x5C9JTnqxrOk7yI69x7oBRMMUtVlZhmuD eV1c/Y/OO6hf2osRz3NeC8Pd6nKHBitVM8VJ/eKDrsKjXkNWK8BljnFdPPkUN7aN 3pfrPno1BfarCMgBZw6v1CZrxr2tLR5HIbgrv+z+HiHv5h9+vcC4UZYPCKy//Bkz jouheolCZkBQ2c5JdEEKb05FkOLFKbP8oZnl6Zjxe/0Jwsk1IKG34gxXK57TrFh9 sqEtOGsZgqlzOxTJF9tZCGGilrH9+U75Nz48NF8pPAsEehVAF2WaYv+JjWnTxWu/ GYhtF3k0a7Y/pBxY3yVb+cDg57soXwafn6C3dG/ZoA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:45:16 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 9f0b60d6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:45:02 +0000 (UTC) Date: Wed, 29 May 2024 14:45:14 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 15/19] imap-send: drop global `imap_server_conf` variable Message-ID: <18ba9f7b3b8bc81539cd69389e9b60f953f2ae5c.1716983704.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: In "imap-send.c", we have a global `sturct imap_server_conf` variable that keeps track of the configuration of the IMAP server. This variable is being populated mostly via the Git configuration. Refactor the code to allocate the structure on the stack instead of having it globally. This change allows us to track its lifetime more closely. Signed-off-by: Patrick Steinhardt --- imap-send.c | 57 ++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/imap-send.c b/imap-send.c index 8b723b34a5..67a7a6c456 100644 --- a/imap-send.c +++ b/imap-send.c @@ -82,10 +82,6 @@ struct imap_server_conf { char *auth_method; }; -static struct imap_server_conf server = { - .ssl_verify = 1, -}; - struct imap_socket { int fd[2]; SSL *ssl; @@ -110,6 +106,7 @@ struct imap { }; struct imap_store { + const struct imap_server_conf *cfg; /* currently open mailbox */ const char *name; /* foreign! maybe preset? */ int uidvalidity; @@ -194,8 +191,8 @@ static void socket_perror(const char *func, struct imap_socket *sock, int ret) #ifdef NO_OPENSSL static int ssl_socket_connect(struct imap_socket *sock UNUSED, - int use_tls_only UNUSED, - int verify UNUSED) + const struct imap_server_conf *cfg, + int use_tls_only UNUSED) { fprintf(stderr, "SSL requested but SSL support not compiled in\n"); return -1; @@ -250,7 +247,9 @@ static int verify_hostname(X509 *cert, const char *hostname) cname, hostname); } -static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int verify) +static int ssl_socket_connect(struct imap_socket *sock, + const struct imap_server_conf *cfg, + int use_tls_only) { #if (OPENSSL_VERSION_NUMBER >= 0x10000000L) const SSL_METHOD *meth; @@ -279,7 +278,7 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve if (use_tls_only) SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3); - if (verify) + if (cfg->ssl_verify) SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL); if (!SSL_CTX_set_default_verify_paths(ctx)) { @@ -306,9 +305,9 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve * OpenSSL does not document this function, but the implementation * returns 1 on success, 0 on failure after calling SSLerr(). */ - ret = SSL_set_tlsext_host_name(sock->ssl, server.host); + ret = SSL_set_tlsext_host_name(sock->ssl, cfg->host); if (ret != 1) - warning("SSL_set_tlsext_host_name(%s) failed.", server.host); + warning("SSL_set_tlsext_host_name(%s) failed.", cfg->host); #endif ret = SSL_connect(sock->ssl); @@ -317,12 +316,12 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve return -1; } - if (verify) { + if (cfg->ssl_verify) { /* make sure the hostname matches that of the certificate */ cert = SSL_get_peer_certificate(sock->ssl); if (!cert) return error("unable to get peer certificate."); - if (verify_hostname(cert, server.host) < 0) + if (verify_hostname(cert, cfg->host) < 0) return -1; } @@ -895,7 +894,7 @@ static int auth_cram_md5(struct imap_store *ctx, const char *prompt) int ret; char *response; - response = cram(prompt, server.user, server.pass); + response = cram(prompt, ctx->cfg->user, ctx->cfg->pass); ret = socket_write(&ctx->imap->buf.sock, response, strlen(response)); if (ret != strlen(response)) @@ -935,6 +934,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c CALLOC_ARRAY(ctx, 1); + ctx->cfg = srvc; ctx->imap = CALLOC_ARRAY(imap, 1); imap->buf.sock.fd[0] = imap->buf.sock.fd[1] = -1; imap->in_progress_append = &imap->in_progress; @@ -1035,7 +1035,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c imap->buf.sock.fd[1] = dup(s); if (srvc->use_ssl && - ssl_socket_connect(&imap->buf.sock, 0, srvc->ssl_verify)) { + ssl_socket_connect(&imap->buf.sock, srvc, 0)) { close(s); goto bail; } @@ -1068,8 +1068,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c if (!srvc->use_ssl && CAP(STARTTLS)) { if (imap_exec(ctx, NULL, "STARTTLS") != RESP_OK) goto bail; - if (ssl_socket_connect(&imap->buf.sock, 1, - srvc->ssl_verify)) + if (ssl_socket_connect(&imap->buf.sock, srvc, 1)) goto bail; /* capabilities may have changed, so get the new capabilities */ if (imap_exec(ctx, NULL, "CAPABILITY") != RESP_OK) @@ -1299,23 +1298,24 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs) static int git_imap_config(const char *var, const char *val, const struct config_context *ctx, void *cb) { + struct imap_server_conf *cfg = cb; if (!strcmp("imap.sslverify", var)) - server.ssl_verify = git_config_bool(var, val); + cfg->ssl_verify = git_config_bool(var, val); else if (!strcmp("imap.preformattedhtml", var)) - server.use_html = git_config_bool(var, val); + cfg->use_html = git_config_bool(var, val); else if (!strcmp("imap.folder", var)) - return git_config_string(&server.folder, var, val); + return git_config_string(&cfg->folder, var, val); else if (!strcmp("imap.user", var)) - return git_config_string(&server.user, var, val); + return git_config_string(&cfg->user, var, val); else if (!strcmp("imap.pass", var)) - return git_config_string(&server.pass, var, val); + return git_config_string(&cfg->pass, var, val); else if (!strcmp("imap.tunnel", var)) - return git_config_string(&server.tunnel, var, val); + return git_config_string(&cfg->tunnel, var, val); else if (!strcmp("imap.authmethod", var)) - return git_config_string(&server.auth_method, var, val); + return git_config_string(&cfg->auth_method, var, val); else if (!strcmp("imap.port", var)) - server.port = git_config_int(var, val, ctx->kvi); + cfg->port = git_config_int(var, val, ctx->kvi); else if (!strcmp("imap.host", var)) { if (!val) { return config_error_nonbool(var); @@ -1324,11 +1324,11 @@ static int git_imap_config(const char *var, const char *val, val += 5; else if (starts_with(val, "imaps:")) { val += 6; - server.use_ssl = 1; + cfg->use_ssl = 1; } if (starts_with(val, "//")) val += 2; - server.host = xstrdup(val); + cfg->host = xstrdup(val); } } else return git_default_config(var, val, ctx, cb); @@ -1497,12 +1497,15 @@ static int curl_append_msgs_to_imap(struct imap_server_conf *server, int cmd_main(int argc, const char **argv) { + struct imap_server_conf server = { + .ssl_verify = 1, + }; struct strbuf all_msgs = STRBUF_INIT; int total; int nongit_ok; setup_git_directory_gently(&nongit_ok); - git_config(git_imap_config, NULL); + git_config(git_imap_config, &server); argc = parse_options(argc, (const char **)argv, "", imap_send_options, imap_send_usage, 0); From patchwork Wed May 29 12:45:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678803 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 9B14CD53E for ; Wed, 29 May 2024 12:45:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986725; cv=none; b=hGI0sabTO8nw6deLG4M2SpyRXo7yyVmUSQlN80VfCJNKCxcoDAuod62y7dkqBteb7FqjepXncoB7H7C1dYEZYbbXUTKOf6dL1FXc6dtS2SH9cLOLM3DKfH6RhGZ8DMqn8KD1rjZLrsGxCxFwMFNTC7YdCYGOxgxN576uigBZ83A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986725; c=relaxed/simple; bh=BeBkimuBCKfvoI2swUJQhGJ7vBPZswX7hhmbwZUcyfo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bcQHKkW5NGfU9aiwgWOk6/Ia2does24gmn/SDoY+oNhghMCbih6Odevf4kE5SFUQMj7MAD6ZkIPJuHceQ4P0WD4gHfPnLWHTMGJXeHTh1fL/Itoou8wz+7TcY3ypr+grmUNlHrUuPUprSjqiroZnCWtTbTDrxHZwZJZNmY6MMHU= 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=c1LGw+Fb; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MyczqFda; arc=none smtp.client-ip=64.147.123.147 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="c1LGw+Fb"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MyczqFda" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id C26CE1C000BF; Wed, 29 May 2024 08:45:22 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 29 May 2024 08:45:22 -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=1716986722; x=1717073122; bh=IlgB8xJagF MZowOS2UKIPQCWu1xA01C9yK/DRIYjt/g=; b=c1LGw+FbH99OxLLEj4xXuB+dyH moLxS8w86osoVmdv7d2P9T7v++aABGCxpjCCJdtAFECBZyKyYU0dZrMkmbdYsO2G YsuBCQpctQAtYcRd1GyfrqMb8gGHvH++VVczLsRMRr2vuYen6Yfxp0SMCL8CwO7k PjaWdwiIVMDsswHQcu17bSMga/trggrpxYJpWwMd4lEjucHuTDVj026uwFFudokq kDJnIxXTyo5QhXSdE8aacKy3IR4VFxj5qNbkNcjmVBAiFRYZ1KhcMFe1lVfHDpC6 hAkHV+tX//NOqfguC+Fhpzsg47aLGb/BUqZquKbtooszT3wDYY5wXJNIEu1Q== 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=1716986722; x=1717073122; bh=IlgB8xJagFMZowOS2UKIPQCWu1xA 01C9yK/DRIYjt/g=; b=MyczqFdae25+K+EurreudXPyftbYoA3DPnp/og8Rol/n wPB1aCEF2+Dfa1zlAHwUVw5muJd7otZhlCMk+CGDOPvNKjKnogMQBrQNEkwpb9yL 381nTwKaDD+PUTlzGh7gDvbKwEC9tfQLDUIr8Lnellrfyte9SDxPST6IDGS08sKR CsIn+ffeF+7FQxEh1FjN1wSaDTJQjAYuw7+VlcM0qYHxLBp0E90jXt6ED3wcS4XG ZmddWpBazDqHmGDfQ1PmKBcnsbsf8bJyhfz6JQHiE0tkmNfuBw1PNNmQo/jeSK4X Imteg9pEzBFHrB2++Apl/mizjnOYVv+Z1qcSAzrmQg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeefnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:45:21 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 0ca2dd84 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:45:06 +0000 (UTC) Date: Wed, 29 May 2024 14:45:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 16/19] imap-send: fix leaking memory in `imap_server_conf` Message-ID: <357d69fa8b538baba23cd110b8d16174234a58dc.1716983704.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: We never free any of the config strings that we populate into the `struct imap_server_conf`. Fix this by creating a common exit path where we can free resources. While at it, drop the unused variables `imap_server_conf::name` and `nongit_ok`. Signed-off-by: Patrick Steinhardt --- imap-send.c | 68 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/imap-send.c b/imap-send.c index 67a7a6c456..a6fb33806c 100644 --- a/imap-send.c +++ b/imap-send.c @@ -69,7 +69,6 @@ static void imap_warn(const char *, ...); static char *next_arg(char **); struct imap_server_conf { - const char *name; char *tunnel; char *host; int port; @@ -1300,23 +1299,28 @@ static int git_imap_config(const char *var, const char *val, { struct imap_server_conf *cfg = cb; - if (!strcmp("imap.sslverify", var)) + if (!strcmp("imap.sslverify", var)) { cfg->ssl_verify = git_config_bool(var, val); - else if (!strcmp("imap.preformattedhtml", var)) + } else if (!strcmp("imap.preformattedhtml", var)) { cfg->use_html = git_config_bool(var, val); - else if (!strcmp("imap.folder", var)) + } else if (!strcmp("imap.folder", var)) { + FREE_AND_NULL(cfg->folder); return git_config_string(&cfg->folder, var, val); - else if (!strcmp("imap.user", var)) + } else if (!strcmp("imap.user", var)) { + FREE_AND_NULL(cfg->folder); return git_config_string(&cfg->user, var, val); - else if (!strcmp("imap.pass", var)) + } else if (!strcmp("imap.pass", var)) { + FREE_AND_NULL(cfg->folder); return git_config_string(&cfg->pass, var, val); - else if (!strcmp("imap.tunnel", var)) + } else if (!strcmp("imap.tunnel", var)) { + FREE_AND_NULL(cfg->folder); return git_config_string(&cfg->tunnel, var, val); - else if (!strcmp("imap.authmethod", var)) + } else if (!strcmp("imap.authmethod", var)) { + FREE_AND_NULL(cfg->folder); return git_config_string(&cfg->auth_method, var, val); - else if (!strcmp("imap.port", var)) + } else if (!strcmp("imap.port", var)) { cfg->port = git_config_int(var, val, ctx->kvi); - else if (!strcmp("imap.host", var)) { + } else if (!strcmp("imap.host", var)) { if (!val) { return config_error_nonbool(var); } else { @@ -1330,8 +1334,9 @@ static int git_imap_config(const char *var, const char *val, val += 2; cfg->host = xstrdup(val); } - } else + } else { return git_default_config(var, val, ctx, cb); + } return 0; } @@ -1502,9 +1507,9 @@ int cmd_main(int argc, const char **argv) }; struct strbuf all_msgs = STRBUF_INIT; int total; - int nongit_ok; + int ret; - setup_git_directory_gently(&nongit_ok); + setup_git_directory_gently(NULL); git_config(git_imap_config, &server); argc = parse_options(argc, (const char **)argv, "", imap_send_options, imap_send_usage, 0); @@ -1529,42 +1534,55 @@ int cmd_main(int argc, const char **argv) if (!server.folder) { fprintf(stderr, "no imap store specified\n"); - return 1; + ret = 1; + goto out; } if (!server.host) { if (!server.tunnel) { fprintf(stderr, "no imap host specified\n"); - return 1; + ret = 1; + goto out; } - server.host = "tunnel"; + server.host = xstrdup("tunnel"); } /* read the messages */ if (strbuf_read(&all_msgs, 0, 0) < 0) { error_errno(_("could not read from stdin")); - return 1; + ret = 1; + goto out; } if (all_msgs.len == 0) { fprintf(stderr, "nothing to send\n"); - return 1; + ret = 1; + goto out; } total = count_messages(&all_msgs); if (!total) { fprintf(stderr, "no messages to send\n"); - return 1; + ret = 1; + goto out; } /* write it to the imap server */ if (server.tunnel) - return append_msgs_to_imap(&server, &all_msgs, total); - + ret = append_msgs_to_imap(&server, &all_msgs, total); #ifdef USE_CURL_FOR_IMAP_SEND - if (use_curl) - return curl_append_msgs_to_imap(&server, &all_msgs, total); + else if (use_curl) + ret = curl_append_msgs_to_imap(&server, &all_msgs, total); #endif - - return append_msgs_to_imap(&server, &all_msgs, total); + else + ret = append_msgs_to_imap(&server, &all_msgs, total); + +out: + free(server.tunnel); + free(server.host); + free(server.folder); + free(server.user); + free(server.pass); + free(server.auth_method); + return ret; } From patchwork Wed May 29 12:45:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678804 Received: from wfhigh6-smtp.messagingengine.com (wfhigh6-smtp.messagingengine.com [64.147.123.157]) (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 4AD02FC18 for ; Wed, 29 May 2024 12:45:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986729; cv=none; b=HiKTDNU0UVdvN+5FPbkMil4lNTcp6KYcDYvd2skFg8QS+g4kP6VM/iIy3fu8MTDrMcYSi9XitPLoGrDeg4XImb59DpFfPg3qMu4k2XrB6N5AopSD8YW2YuBcUaW/RZrbyA9csiU3+cxGGn0fRq6bUVH1LZF5RXNgW/eNgqaLJAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986729; c=relaxed/simple; bh=a4UYU5oTgOdRXsPQfQWNDAejQS+pdoVEoMz8Oa7xOYo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WEaX5wvDPp0NMLAaoHKgIVjxors1e0aLo3b+3dQoER/lB0yv7bAhi0cnWbFT+WUsuyc0i7hihoXZraEgDVrN9hRWMRuYvtfcpl5HfLe8aJyZIcKeFgEBxuc32ckPe1Dq14EN3aHaGjQSIKX4cYh0tj/aXfmqV+DxL9wUXJsPIJE= 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=dPyAR9zs; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Gb/rcT1N; arc=none smtp.client-ip=64.147.123.157 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="dPyAR9zs"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Gb/rcT1N" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.west.internal (Postfix) with ESMTP id 86FB81800116; Wed, 29 May 2024 08:45:27 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 29 May 2024 08:45:27 -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=1716986727; x=1717073127; bh=eSG9/Sv/aP tLLKOoKAsckCx3k9HlNGqhzRzpg3U8b5U=; b=dPyAR9zsL/EbzteLw7FoHJ/bmG uRGO7PvxMY8rpyULhrB/rEub5MLj8AyCARFl34vmkOPENNiiyNBr10D272xot22O V8NYxBZS3FujkQtIGyybYIfefqyjFBhTYwIaHZkxpLiERw1r241PQzV1tmjyGLVA bwlZIyvfHeGciZhTdGQxMSLjcC9W+KV7hfVcCdtqooC6K53aa7BzZNmJVU9mFlhN 9EkoWyobACczfbLLfu1sQlGxAMC4KA66uDlwzpOrVuc7vtcsfj3yafJuX9siSbhR KkSjvu2dxRcH5Y9z/0Ujl5tI/FYT8HXf2hiPTzknr4vKwBEg03yKwQrBQing== 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=1716986727; x=1717073127; bh=eSG9/Sv/aPtLLKOoKAsckCx3k9Hl NGqhzRzpg3U8b5U=; b=Gb/rcT1NuPzmcIZcKGzauy0JsbB01oCEbjljQvvBclVj iwL3vA1e2jPY64h5k8R8uPLxAmT8IfzvAu7teccJPkbiNr91NNqKJC5jhGEMH5mJ izTTok0ZFrfOSvhvPJOLwoKTqiHEUmP2dyJ+FzMN/NddDbwdulSHBBPW+hmtTK6K y1oWTqh+D5GMHzArJ9FVpgiUMRdZ1U7B7eB8rWTbWCliwLA6aqmRvAz6bpes67dt TrCK+5IPzE+PflLtpfx6602VY+ddOQhF642wIYWQE0IG4i5B4vAOfnuvFULNhMqu NeoxvP3Nkw4CXI+u7WCkr0eiSRioJeBCUjGJ7YQBHg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpefgfedvfefffedvffefudeiuddtteeggf duieeuvdefiedtjeeufeeuieelueekfeenucffohhmrghinhepshhtrhgrthgvghihpgho phhtshdrnhhrnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:45:26 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id e25543a6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:45:11 +0000 (UTC) Date: Wed, 29 May 2024 14:45:23 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 17/19] builtin/rebase: adapt code to not assign string constants to non-const Message-ID: <16d3d28243a0480c929ae3740db92ade238dd325.1716983704.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: When computing the rebase strategy we temporarily assign a string constant to `options.strategy` before we call `xstrdup()` on it. Furthermore, the default backend is being assigned a string constant via `REBASE_OPTIONS_INIT`. Both of these will cause warnings once we enable `-Wwrite-strings`. Adapt the code such that we only store allocated strings in those variables. Signed-off-by: Patrick Steinhardt --- builtin/rebase.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 14d4f0a5e6..b05c3b6be3 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -135,7 +135,6 @@ struct rebase_options { .type = REBASE_UNSPECIFIED, \ .empty = EMPTY_UNSPECIFIED, \ .keep_empty = 1, \ - .default_backend = "merge", \ .flags = REBASE_NO_QUIET, \ .git_am_opts = STRVEC_INIT, \ .exec = STRING_LIST_INIT_NODUP, \ @@ -796,6 +795,7 @@ static int rebase_config(const char *var, const char *value, } if (!strcmp(var, "rebase.backend")) { + FREE_AND_NULL(opts->default_backend); return git_config_string(&opts->default_backend, var, value); } @@ -1471,12 +1471,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } if (options.strategy_opts.nr && !options.strategy) - options.strategy = "ort"; - - if (options.strategy) { - options.strategy = xstrdup(options.strategy); + options.strategy = xstrdup("ort"); + else + options.strategy = xstrdup_or_null(options.strategy); + if (options.strategy) imply_merge(&options, "--strategy"); - } if (options.root && !options.onto_name) imply_merge(&options, "--root without --onto"); @@ -1522,7 +1521,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } if (options.type == REBASE_UNSPECIFIED) { - if (!strcmp(options.default_backend, "merge")) + if (!options.default_backend) + options.type = REBASE_MERGE; + else if (!strcmp(options.default_backend, "merge")) options.type = REBASE_MERGE; else if (!strcmp(options.default_backend, "apply")) options.type = REBASE_APPLY; @@ -1833,6 +1834,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) cleanup: strbuf_release(&buf); strbuf_release(&revisions); + free(options.default_backend); free(options.reflog_action); free(options.head_name); strvec_clear(&options.git_am_opts); From patchwork Wed May 29 12:45:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678805 Received: from wfhigh6-smtp.messagingengine.com (wfhigh6-smtp.messagingengine.com [64.147.123.157]) (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 151BAD53E for ; Wed, 29 May 2024 12:45:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986736; cv=none; b=EqWaJQgZzYja87+4knairhWea6m4Wrt6W+ysGuUBmBKOcihe8VTNwIxxO+t13P8KjWaSHraiYvrksVp+s7PBfTyzPF0t7GjVWwpI5NG+9PL35DbmrCR0m1veVNxNKZafkQMsKpI1GLvoEEl+pIid+QkjylCOEXJdc8QsqpHsfZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986736; c=relaxed/simple; bh=f2CtYVYutxg7K82bLzhnwsNZnf7Icqsxu4VYqTxO6zU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GMsPZdOPxAMis2JgDTrIjrZZj6+2dRVya7+VW7yV5PspnDU6vskTyNAUDzOubFaHm2n0nvy52ookvnOIHABUjsiN9MKVR5btlZrYq3EXUKm8rcdlRvRutdd8C3+TfcNANQR2I9DO7Th/FpndCahLmIFZy9DSuAQzOMuBMN16zVQ= 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=ZGFa5V7O; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Rl1mTXjW; arc=none smtp.client-ip=64.147.123.157 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="ZGFa5V7O"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Rl1mTXjW" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id 388681800116; Wed, 29 May 2024 08:45:34 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 29 May 2024 08:45:34 -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=1716986733; x=1717073133; bh=n7gx9gQMSI tbYSxSOsbsFZNpg7XG7OifRLQBfVVRad4=; b=ZGFa5V7OirO8Y5d2ABcm4lT1yn QwXuUduHVGXrlwLrPaK4oiVaq16R8OWtDbu2DX3noYptZcqf4PfN3wAknAo3+6tI ikyRmb+Iz/JzM5qG38JW0Rfv7sTfwqD1HkD5kBbCeRKxe3BTupjgAyAxzf4s6FZI PkNq0B8j26b6VMoUxy7lVg0bit266TP/nG660ODuNd29ugvqPrNVqxV3RVqqK7o2 Qsh8tXOtoJAuhqOfU7k0LjWZcabgjlA3H76zzrFyAfJc6ELSWI1nxIkd9F+UWs7p kULdC3vyNmgtPt6RaE2fCeo5Gx0P/A2MqVJ1GbYrA912l55o8DJOLmfWUPCg== 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=1716986733; x=1717073133; bh=n7gx9gQMSItbYSxSOsbsFZNpg7XG 7OifRLQBfVVRad4=; b=Rl1mTXjWdPa7/MgviFy8gWvn4kgOOakpQe3VTq0PiIol N9cKp5RQ7hAxHaDTef518DGgDs109V7lD5cfF3wBfbK0ITd0im5AGhxmI5CQEgId 4LYTg/Q3OjhmuAXnYkVaJmwSnYzjeWbkf4fElMIr3G4dWuQ55tL+tWbibUaBMxib AUHooLVTJd/HccYLszQWUa4VBOaUimldPaDQZTQFuL7JL+0hw8LzQJgndjOWB9kU cQKK0znhPAo5T8gMGI6pEcUDWnxNKgk/JGZuWqiC735xrWOwiIJeuSLR8FSlnpPl ZoR6OL3ALpQj6yPyqRbQVbeNDSeRkhNYJY75ipf+UA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:45:32 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id b07f0242 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:45:18 +0000 (UTC) Date: Wed, 29 May 2024 14:45:30 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 18/19] builtin/merge: always store allocated strings in `pull_twohead` Message-ID: <129482dbaa64b509f103914e8b3d6bdd14f47b62.1716983704.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 `pull_twohead` configuration may sometimes contain an allocated string, and sometimes it may contain a string constant. Refactor this to instead always store an allocated string such that we can release its resources without risk. While at it, manage the lifetime of other config strings, as well. Note that we explicitly don't free `cleanup_arg` here. This is because the variable may be assigned a string constant via command line options. Signed-off-by: Patrick Steinhardt --- builtin/merge.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/builtin/merge.c b/builtin/merge.c index daed2d4e1e..fb3eb15b89 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -611,17 +611,19 @@ static int git_merge_config(const char *k, const char *v, return 0; } - if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat")) + if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat")) { show_diffstat = git_config_bool(k, v); - else if (!strcmp(k, "merge.verifysignatures")) + } else if (!strcmp(k, "merge.verifysignatures")) { verify_signatures = git_config_bool(k, v); - else if (!strcmp(k, "pull.twohead")) + } else if (!strcmp(k, "pull.twohead")) { + FREE_AND_NULL(pull_twohead); return git_config_string(&pull_twohead, k, v); - else if (!strcmp(k, "pull.octopus")) + } else if (!strcmp(k, "pull.octopus")) { + FREE_AND_NULL(pull_octopus); return git_config_string(&pull_octopus, k, v); - else if (!strcmp(k, "commit.cleanup")) + } else if (!strcmp(k, "commit.cleanup")) { return git_config_string(&cleanup_arg, k, v); - else if (!strcmp(k, "merge.ff")) { + } else if (!strcmp(k, "merge.ff")) { int boolval = git_parse_maybe_bool(v); if (0 <= boolval) { fast_forward = boolval ? FF_ALLOW : FF_NO; @@ -1294,7 +1296,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (!pull_twohead) { char *default_strategy = getenv("GIT_TEST_MERGE_ALGORITHM"); if (default_strategy && !strcmp(default_strategy, "ort")) - pull_twohead = "ort"; + pull_twohead = xstrdup("ort"); } init_diff_ui_defaults(); @@ -1793,6 +1795,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix) } strbuf_release(&buf); free(branch_to_free); + free(pull_twohead); + free(pull_octopus); discard_index(the_repository->index); return ret; } From patchwork Wed May 29 12:45:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678806 Received: from wfhigh6-smtp.messagingengine.com (wfhigh6-smtp.messagingengine.com [64.147.123.157]) (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 A77ED12E5B for ; Wed, 29 May 2024 12:45:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986741; cv=none; b=AcP+EhcS9RUmaID7bp9cyDrcCS1xFa4hT33IASWvu02PGZeP4fmkBUMpc+LiouOCqD/9nvU5d/VP7LoeLHGvMoXdnSucV4Savyx+XCfz1ceyB1CHmT61DbubtFxMUniD0fasPRPL2qFFerXUGhi+hiuH0sCPvt96XLOyJ/7gbdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986741; c=relaxed/simple; bh=gXbJs77wQdZ5la+RCoUDgSdpfGztRSu4HTdgw5H0Ops=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=awtRiO53ZCiX36cLqLvi85dZ0m67gnFpJoPEoX1Dde9WCFnhDSKs2sYrCd70Gh84VSo5/N9zko6Gux7xgbuvgh4wDpA464fLE4DNAp7v9MZIBLcykTTRkpCEPKGeaXhQ6C+7N6iGE0q1qewG8MDx69Tl5an1G7eVjD2TYhkAxYs= 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=RetuSXQf; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=a+kcBbze; arc=none smtp.client-ip=64.147.123.157 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="RetuSXQf"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="a+kcBbze" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id 007AC180011B; Wed, 29 May 2024 08:45:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 29 May 2024 08:45:39 -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=1716986738; x=1717073138; bh=gXbJs77wQd Z5la+RCoUDgSdpfGztRSu4HTdgw5H0Ops=; b=RetuSXQfwwIGsOhtZOD9107Gba N03Z0jMfG1ZPK/UyCrmuTH74GKZ9o5H/5l+pA5inwVfla1ydRHBR7oMxsjYvYx6Z 9NBx0/Kmoz3bZ4A1G87hGYN+Kpxzu1nKD6QR74cK6YETpyUOH7VLo3IZP3lJ4keV e4jb73uvbvat8/VqMIk9YHq18N7dDtD9bADSAmYfqOLl0BAxnejQVwJmKJuShCoe WCF67z8jr9gKtmg1jxh0ZFDdi3VzfR4lvkyniFCDHTRFHQnekHBBnMVsY8HJLc26 TsvzUdI599gPb6ot6rT82E/yI3+ZGLBI9r11oZV1lrdYY+wcXC1nTbmfVZ+Q== 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=1716986738; x=1717073138; bh=gXbJs77wQdZ5la+RCoUDgSdpfGzt RSu4HTdgw5H0Ops=; b=a+kcBbzeuUyQRalln68lu+hkPdJpv21pCODSuc6dbhKS 0jvGTCY7PBOGoDphPhG4GnLg8cN003xgs2d1nOP5VGKlv1BbT8NI2Rzh6SzHejv7 avb+J7uc1rzeEO4uYe66tL1iFscVSaSVvvbSQ/B+ONoqktDOOQTLV+LGtdK2y5e0 8r/AoU/97XqCBO9LgRDqmysZx3vOY260N6bsIAZX0nSNobO8Zbrvgk88tcWNabdo u0e6bZ8sC6RPIBavhKaDX6sypO0uT9czigOvrpe2f+4oHXt/WfjWNX8+j1EKv/k2 LtnSf/h49LVcEVALBeHLhoMwegDp4ej+XyYldo/+Uw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpedtkeefgeeiiedugfdvgeeffffgtdehge efieetffekleetgeffvdfhveejudejtdenucffohhmrghinhepmhgrkhdruggvvhenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhksh drihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:45:37 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id fff5cd66 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:45:23 +0000 (UTC) Date: Wed, 29 May 2024 14:45:35 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 19/19] config.mak.dev: enable `-Wwrite-strings` warning Message-ID: <37e7aaed97df0b902631e76ba82ee7c6473293ad.1716983704.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: Writing to string constants is undefined behaviour and must be avoided in C. Even so, the compiler does not help us with this by default because those constants are not in fact marked as `const`. This makes it rather easy to accidentally assign a constant to a non-const variable or field and then later on try to either free it or write to it. Enable `-Wwrite-strings` to catch such mistakes. With this warning enabled, the type of string constants is changed to `const char[]` and will thus cause compiler warnings when being assigned to non-const fields and variables. Signed-off-by: Patrick Steinhardt --- config.mak.dev | 1 + 1 file changed, 1 insertion(+) diff --git a/config.mak.dev b/config.mak.dev index 981304727c..1ce4c70613 100644 --- a/config.mak.dev +++ b/config.mak.dev @@ -37,6 +37,7 @@ DEVELOPER_CFLAGS += -Wpointer-arith DEVELOPER_CFLAGS += -Wstrict-prototypes DEVELOPER_CFLAGS += -Wunused DEVELOPER_CFLAGS += -Wvla +DEVELOPER_CFLAGS += -Wwrite-strings DEVELOPER_CFLAGS += -fno-common ifneq ($(filter clang4,$(COMPILER_FEATURES)),)