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: Re: [PATCH v2 2/2] ci: compile "linux-gcc-default" job with -Og
Date: Fri, 07 Jun 2024 13:35:28 -0700	[thread overview]
Message-ID: <xmqq34pofq3z.fsf@gitster.g> (raw)
In-Reply-To: <xmqqed98d1wn.fsf@gitster.g> (Junio C. Hamano's message of "Fri, 07 Jun 2024 11:48:56 -0700")

Junio C Hamano <gitster@pobox.com> writes:

>   pack-mtimes.c: In function ‘load_pack_mtimes_file’:
>   Error: pack-mtimes.c:89:25: ‘mtimes_size’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>      89 |                         munmap(data, mtimes_size);
>         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~
>   cc1: all warnings being treated as errors
>   make: *** [Makefile:2757: pack-mtimes.o] Error 1
>   make: *** Waiting for unfinished jobs....

The use on line 89 is guarded with "if (data)" and data can become
non-NULL only after mtimes_size is computed, so this is benign.

They have excuse for a false positive because the warning is about
"maybe" uninitialized, but that does not help our annoyance factor
X-<.

>   pack-revindex.c: In function ‘load_revindex_from_disk’:
>   Error: pack-revindex.c:260:25: ‘revindex_size’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>     260 |                         munmap(data, revindex_size);
>         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>   cc1: all warnings being treated as errors
>   make: *** [Makefile:2757: pack-revindex.o] Error 1
>   cat: exit.status: No such file or directory

This follows exactly the same pattern established by the other one
(or perhaps the other one copied from here).  It is another false
positive.

I am not sure what the right fix would be.  For example, if we were
interested in avoiding to incur too much resources for revindex, we
might do something like this

--- i/pack-revindex.c
+++ w/pack-revindex.c
@@ -258,6 +258,8 @@ static int load_revindex_from_disk(char *revindex_name,
 	if (ret) {
 		if (data)
 			munmap(data, revindex_size);
+		fprintf(stderr, "would have fit %d revindex in 10MB\n",
+			10 * 1024 * 1024 / revindex_size);
 	} else {
 		*len_p = revindex_size;
 		*data_p = (const uint32_t *)data;

without even guarding with "if (data)".

If we "initialize" revindex_size to a meaningless dummy value like 0
like the attached would _hide_ such a real bug from the compiler, so
I dunno.

@@ -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 = 0;
 	struct revindex_header *hdr;
 
 	if (git_env_bool(GIT_TEST_REV_INDEX_DIE_ON_DISK, 0))

  reply	other threads:[~2024-06-07 20:35 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 [this message]
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       ` [PATCH 1/2] DONTAPPLY: -Og fallout workaround Junio C Hamano
2024-06-10 20:05         ` 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=xmqq34pofq3z.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).