Re: [PATCH] read-cache: fix division by zero core-dump
- From
Ben Peart <peartben@gmail.com>
- Date
- Sep 28, 2018, 01:20 UTC
- Message-ID
- <8a76234e-fcf8-f435-33e9-1846c3b6ad14@gmail.com>
- In-Reply-To
- <476b5678-41b2-d2f8-1890-ba315354ebc0@ramsayjones.plus.com>
On 9/27/2018 6:24 PM, Ramsay Jones wrote:
Show 17 quoted lines
>
> commit 225df8a468 ("ieot: add Index Entry Offset Table (IEOT)
> extension", 2018-09-26) added a 'DIV_ROUND_UP(entries, ieot_blocks)
> expression, where ieot_blocks was set to zero for a single cpu
> platform. This caused an SIGFPE and a core dump in practically
> every test in the test-suite, until test t4056-diff-order.sh, which
> then went into an infinite loop!
>
> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
> ---
>
> Hi Ben,
>
> Could you please squash this into the relevant commits on your
> 'bp/read-cache-parallel' branch. (The first hunk fixes a sparse
> warning about using an integer as a NULL pointer).
> Absolutely - thanks for the patch.
I don't know how long it's been since I've been on a single core CPU - I'm sad for you. ;-)
Show 31 quoted lines
> Thanks!
>
> ATB,
> Ramsay Jones
>
> read-cache.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/read-cache.c b/read-cache.c
> index 6755d58877..40f096f70a 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -2141,7 +2141,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
> size_t extension_offset = 0;
> #ifndef NO_PTHREADS
> int nr_threads, cpus;
> - struct index_entry_offset_table *ieot = 0;
> + struct index_entry_offset_table *ieot = NULL;
> #endif
>
> if (istate->initialized)
> @@ -2771,7 +2771,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
> if (ieot_blocks < 1)
> ieot_blocks = 1;
> cpus = online_cpus();
> - if (ieot_blocks > cpus - 1)
> + if (cpus > 1 && ieot_blocks > cpus - 1)
> ieot_blocks = cpus - 1;
> } else {
> ieot_blocks = nr;
>