git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 4/4] load_pack_mtimes_file(): avoid accessing uninitialized data

From
Taylor Blau <me@ttaylorr.com>
Date
Mar 27, 2025, 14:24 UTC
Message-ID
<Z+VfmZ4RZ5OjU/ed@nand.local>
In-Reply-To
<d630e95b9672e6b4b3114c077f2995c5170a6a8f.1743079429.git.gitgitgadget@gmail.com>
On Thu, Mar 27, 2025 at 12:43:49PM +0000, Johannes Schindelin via GitGitGadget wrote:
Show 20 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> The `mtimes_size` variable is uninitialzed when the function errors out,
> yet its value is assigned to another variable. Let's just initialize it.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  pack-mtimes.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/pack-mtimes.c b/pack-mtimes.c
> index cdf30b8d2b0..c1f531d45a0 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 = 0, expected_size;

Hmm. This one follows an identical line of reasoning as in my previous response in the thread. So I think this one is likewise unnecessary (though not harmful, and certainly useful if it appeases static analysis tools, etc).

Thanks, Taylor

Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin
Message 9 of 10 in “Initialize a few uninitialized variables”
  1. 0/4 Initialize a few uninitialized variablesJohannes Schindelin via GitGitGadget, Mar 27, 2025
  2. 1/4 cat_one_file(): make it easy to see that the `size` variable is initializedJohannes Schindelin via GitGitGadget, Mar 27, 2025
  3. Jeff KingMar 28, 2025
  4. 2/4 fsck: avoid using an uninitialized variableJohannes Schindelin via GitGitGadget, Mar 27, 2025
  5. Jeff KingMar 28, 2025
  6. 3/4 load_revindex_from_disk(): avoid accessing uninitialized dataJohannes Schindelin via GitGitGadget, Mar 27, 2025
  7. Taylor BlauMar 27, 2025
  8. 4/4 load_pack_mtimes_file(): avoid accessing uninitialized dataJohannes Schindelin via GitGitGadget, Mar 27, 2025
  9. Taylor BlauMar 27, 2025
  10. Johannes SchindelinJul 17, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.