git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org,  Jeff King <peff@peff.net>
Subject: [PATCH 1/2] DONTAPPLY: -Og fallout workaround
Date: Mon, 10 Jun 2024 11:36:40 -0700	[thread overview]
Message-ID: <xmqqjziw3arr.fsf@gitster.g> (raw)
In-Reply-To: <xmqqed946auc.fsf@gitster.g> (Junio C. Hamano's message of "Mon, 10 Jun 2024 09:06:51 -0700")

These "workarounds" are to mark variables that are used after
initialized, but some compilers with lower optimization levels
cannot see and report "used uninitialized".

This set targets "gcc-12 -Og".  For the reason why this is a wrong
thing to do for longer-term code health, see

  https://lore.kernel.org/git/xmqqed946auc.fsf@gitster.g/

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * Even though I said I won't do the actual patch, since I had to
   gauge the extent of damage, I ended up doing so anyways.

   As I explained already, the size of this patch, i.e. number of
   places that need the workaround, does not really matter.  What
   is horrible is how each of these workaround will hide real bugs
   we may introduce in the future from the compilers.

 builtin/branch.c          | 2 +-
 builtin/fast-import.c     | 4 ++--
 builtin/repack.c          | 2 +-
 fetch-pack.c              | 2 +-
 http-backend.c            | 2 +-
 http.c                    | 2 +-
 pack-mtimes.c             | 2 +-
 pack-revindex.c           | 2 +-
 refs/packed-backend.c     | 2 +-
 reftable/stack.c          | 2 +-
 remote-curl.c             | 4 ++--
 t/helper/test-ref-store.c | 2 +-
 trailer.c                 | 4 ++--
 13 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 48cac74f97..1f4de92e05 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -504,7 +504,7 @@ static void print_current_branch_name(void)
 	int flags;
 	const char *refname = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
 						      "HEAD", 0, NULL, &flags);
-	const char *shortname;
+	const char *shortname = shortname;
 	if (!refname)
 		die(_("could not resolve HEAD"));
 	else if (!(flags & REF_ISSYMREF))
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index ea5ae5196d..6d53e42011 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1866,7 +1866,7 @@ static void parse_original_identifier(void)
 
 static int parse_data(struct strbuf *sb, uintmax_t limit, uintmax_t *len_res)
 {
-	const char *data;
+	const char *data = data;
 	strbuf_reset(sb);
 
 	if (!skip_prefix(command_buf.buf, "data ", &data))
@@ -2807,7 +2807,7 @@ static void parse_new_commit(const char *arg)
 static void parse_new_tag(const char *arg)
 {
 	static struct strbuf msg = STRBUF_INIT;
-	const char *from;
+	const char *from = from;
 	char *tagger;
 	struct branch *s;
 	struct tag *t;
diff --git a/builtin/repack.c b/builtin/repack.c
index 7608430a37..e4752aae3f 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1106,7 +1106,7 @@ static int write_cruft_pack(const struct pack_objects_args *args,
 
 static const char *find_pack_prefix(const char *packdir, const char *packtmp)
 {
-	const char *pack_prefix;
+	const char *pack_prefix = pack_prefix;
 	if (!skip_prefix(packtmp, packdir, &pack_prefix))
 		die(_("pack prefix %s does not begin with objdir %s"),
 		    packtmp, packdir);
diff --git a/fetch-pack.c b/fetch-pack.c
index eba9e420ea..f8f318742f 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1517,7 +1517,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
 
 	process_section_header(reader, "shallow-info", 0);
 	while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
-		const char *arg;
+		const char *arg = arg;
 		struct object_id oid;
 
 		if (skip_prefix(reader->line, "shallow ", &arg)) {
diff --git a/http-backend.c b/http-backend.c
index 5b4dca65ed..eecba3b44f 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -259,7 +259,7 @@ static void http_config(void)
 
 static struct rpc_service *select_service(struct strbuf *hdr, const char *name)
 {
-	const char *svc_name;
+	const char *svc_name = svc_name;
 	struct rpc_service *svc = NULL;
 	int i;
 
diff --git a/http.c b/http.c
index 2dea2d03da..c45f91fa4e 100644
--- a/http.c
+++ b/http.c
@@ -2156,7 +2156,7 @@ static int update_url_from_redirect(struct strbuf *base,
 				    const char *asked,
 				    const struct strbuf *got)
 {
-	const char *tail;
+	const char *tail = tail;
 	size_t new_len;
 
 	if (!strcmp(asked, got->buf))
diff --git a/pack-mtimes.c b/pack-mtimes.c
index cdf30b8d2b..49598d4749 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -29,7 +29,7 @@ static int load_pack_mtimes_file(char *mtimes_file,
 	int fd, ret = 0;
 	struct stat st;
 	uint32_t *data = NULL;
-	size_t mtimes_size, expected_size;
+	size_t mtimes_size = mtimes_size, expected_size;
 	struct mtimes_header header;
 
 	fd = git_open(mtimes_file);
diff --git a/pack-revindex.c b/pack-revindex.c
index fc63aa76a2..7120bed5b1 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -206,7 +206,7 @@ static int load_revindex_from_disk(char *revindex_name,
 	int fd, ret = 0;
 	struct stat st;
 	void *data = NULL;
-	size_t revindex_size;
+	size_t revindex_size = revindex_size;
 	struct revindex_header *hdr;
 
 	if (git_env_bool(GIT_TEST_REV_INDEX_DIE_ON_DISK, 0))
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index c4c1e36aa2..25321a5758 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -677,7 +677,7 @@ static struct snapshot *create_snapshot(struct packed_ref_store *refs)
 
 	/* If the file has a header line, process it: */
 	if (snapshot->buf < snapshot->eof && *snapshot->buf == '#') {
-		char *tmp, *p, *eol;
+		char *tmp, *p = p, *eol;
 		struct string_list traits = STRING_LIST_INIT_NODUP;
 
 		eol = memchr(snapshot->buf, '\n',
diff --git a/reftable/stack.c b/reftable/stack.c
index 737591125e..aa1851fd73 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -1231,7 +1231,7 @@ struct segment suggest_compaction_segment(uint64_t *sizes, size_t n,
 					  uint8_t factor)
 {
 	struct segment seg = { 0 };
-	uint64_t bytes;
+	uint64_t bytes = bytes;
 	size_t i;
 
 	if (!factor)
diff --git a/remote-curl.c b/remote-curl.c
index 827bd848ae..4f9808c63f 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1265,7 +1265,7 @@ static void parse_fetch(struct strbuf *buf)
 	int alloc_heads = 0, nr_heads = 0;
 
 	do {
-		const char *p;
+		const char *p = p;
 		if (skip_prefix(buf->buf, "fetch ", &p)) {
 			const char *name;
 			struct ref *ref;
@@ -1428,7 +1428,7 @@ static void parse_push(struct strbuf *buf)
 	int ret;
 
 	do {
-		const char *arg;
+		const char *arg = arg;
 		if (skip_prefix(buf->buf, "push ", &arg))
 			strvec_push(&specs, arg);
 		else
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index ad24300170..7d3870fe76 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -66,7 +66,7 @@ static unsigned int arg_flags(const char *arg, const char *name,
 
 static const char **get_store(const char **argv, struct ref_store **refs)
 {
-	const char *gitdir;
+	const char *gitdir = gitdir;
 
 	if (!argv[0]) {
 		die("ref store required");
diff --git a/trailer.c b/trailer.c
index 72e5136c73..5056c16644 100644
--- a/trailer.c
+++ b/trailer.c
@@ -508,11 +508,11 @@ static int git_trailer_config(const char *conf_key, const char *value,
 			      const struct config_context *ctx UNUSED,
 			      void *cb UNUSED)
 {
-	const char *trailer_item, *variable_name;
+	const char *trailer_item = trailer_item, *variable_name;
 	struct arg_item *item;
 	struct conf_info *conf;
 	char *name = NULL;
-	enum trailer_info_type type;
+	enum trailer_info_type type = type;
 	int i;
 
 	if (!skip_prefix(conf_key, "trailer.", &trailer_item))
-- 
2.45.2-445-g1b76f06508


  reply	other threads:[~2024-06-10 18:36 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-06  6:30 [PATCH 0/2] ci: detect more warnings via `-Og` Patrick Steinhardt
2024-06-06  6:30 ` [PATCH 1/2] ci: fix check for Ubuntu 20.04 Patrick Steinhardt
2024-06-06  6:53   ` Jeff King
2024-06-06  7:44     ` Patrick Steinhardt
2024-06-06  6:30 ` [PATCH 2/2] ci: let pedantic job compile with -Og Patrick Steinhardt
2024-06-06  6:52   ` Jeff King
2024-06-06  7:41     ` Patrick Steinhardt
2024-06-06  8:05       ` Jeff King
2024-06-06  8:25         ` Patrick Steinhardt
2024-06-06  9:31         ` [PATCH v2 0/2] ci: detect more warnings via `-Og` Patrick Steinhardt
2024-06-06  9:31           ` [PATCH v2 1/2] ci: fix check for Ubuntu 20.04 Patrick Steinhardt
2024-06-06  9:31           ` [PATCH v2 2/2] ci: compile "linux-gcc-default" job with -Og Patrick Steinhardt
2024-06-06 15:32             ` Justin Tobler
2024-06-06 17:02             ` Junio C Hamano
2024-06-07  5:28               ` Patrick Steinhardt
2024-06-07 18:45                 ` Junio C Hamano
2024-06-08  8:49                   ` Jeff King
2024-06-07 18:48             ` Junio C Hamano
2024-06-07 20:35               ` Junio C Hamano
2024-06-07  6:46         ` [PATCH v3 0/4] ci: detect more warnings via `-Og` Patrick Steinhardt
2024-06-07  6:46           ` [PATCH v3 1/4] ci: fix check for Ubuntu 20.04 Patrick Steinhardt
2024-06-07  6:46           ` [PATCH v3 2/4] Makefile: add ability to append to CFLAGS and LDFLAGS Patrick Steinhardt
2024-06-08  8:55             ` Jeff King
2024-06-08 19:01               ` Junio C Hamano
2024-06-10  7:01                 ` Patrick Steinhardt
2024-06-07  6:46           ` [PATCH v3 3/4] ci: compile code with V=1 Patrick Steinhardt
2024-06-07  6:46           ` [PATCH v3 4/4] ci: compile "linux-gcc-default" job with -Og Patrick Steinhardt
2024-06-07 20:47           ` [PATCH v3 0/4] ci: detect more warnings via `-Og` Junio C Hamano
2024-06-08  9:28             ` Jeff King
2024-06-08 23:12               ` Junio C Hamano
2024-06-10  6:25                 ` Patrick Steinhardt
2024-06-06 16:32     ` [PATCH 2/2] ci: let pedantic job compile with -Og Junio C Hamano
2024-06-07  5:10       ` Patrick Steinhardt
2024-06-07 18:42         ` Junio C Hamano
2024-06-10  6:38 ` [PATCH v4 0/2] ci: detect more warnings via `-Og` Patrick Steinhardt
2024-06-10  6:38   ` [PATCH v4 1/2] Makefile: add ability to append to CFLAGS and LDFLAGS Patrick Steinhardt
2024-06-10  6:38   ` [PATCH v4 2/2] ci: compile "linux-gcc-default" job with -Og Patrick Steinhardt
2024-06-10 16:06     ` Junio C Hamano
2024-06-10 18:36       ` Junio C Hamano [this message]
2024-06-10 20:05         ` [PATCH 1/2] DONTAPPLY: -Og fallout workaround Junio C Hamano
2024-06-11 12:09           ` Patrick Steinhardt
2024-06-11 17:30             ` Junio C Hamano
2024-06-12  4:42               ` Patrick Steinhardt
2024-06-12  4:45                 ` Patrick Steinhardt
2024-06-10 18:36       ` [PATCH 2/2] DONTAPPLY: -Os " Junio C Hamano
2024-06-12 22:11       ` [PATCH v4 2/2] ci: compile "linux-gcc-default" job with -Og Junio C Hamano
2024-06-13 10:15         ` Jeff King
2024-06-13 15:47           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqjziw3arr.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).