[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/3] ipc/mach_debug.c (host_ipc_hash_info): quiet GCC warning
From: |
Richard Braun |
Subject: |
Re: [PATCH 2/3] ipc/mach_debug.c (host_ipc_hash_info): quiet GCC warning about uninitialized variable |
Date: |
Wed, 18 Dec 2013 11:21:46 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Wed, Dec 18, 2013 at 09:17:48AM +0100, Marin Ramesa wrote:
> Don't initialize to zero, rather move the initialization of size before
> the break statement. Break on the first iteration should never happen, so the
> position of initialization doesn't matter.
>
> * ipc/mach_debug.c (host_ipc_hash_info) (size): Don't initialize to zero.
> (host_ipc_hash_info) (size): Move initialization before the break statement.
>
> ---
> ipc/mach_debug.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/ipc/mach_debug.c b/ipc/mach_debug.c
> index dd9057a..d7c454b 100644
> --- a/ipc/mach_debug.c
> +++ b/ipc/mach_debug.c
> @@ -112,7 +112,7 @@ host_ipc_hash_info(
> mach_msg_type_number_t *countp)
> {
> vm_offset_t addr;
> - vm_size_t size = 0; /* Suppress gcc warning */
> + vm_size_t size;
> hash_info_bucket_t *info;
> unsigned int potential, actual;
> kern_return_t kr;
> @@ -127,6 +127,9 @@ host_ipc_hash_info(
>
> for (;;) {
> actual = ipc_hash_info(info, potential);
> +
> + size = round_page(actual * sizeof *info);
> +
> if (actual <= potential)
> break;
>
> @@ -135,7 +138,6 @@ host_ipc_hash_info(
> if (info != *infop)
> kmem_free(ipc_kernel_map, addr, size);
See that kmem_free() right here, it uses the size computed during the
previous iteration. It works as it is because ipc_hash_info returns
ipc_hash_global_size, a value that doesn't change after initialization.
But it will break if the hash table is made resizable.
> - size = round_page(actual * sizeof *info);
> kr = kmem_alloc_pageable(ipc_kernel_map, &addr, size);
> if (kr != KERN_SUCCESS)
> return KERN_RESOURCE_SHORTAGE;
--
Richard Braun
- [PATCH 1/3] ipc: avoid dereference of null pointer and quiet the GCC warning about uninitialized variable, Marin Ramesa, 2013/12/18
- [PATCH 2/3] ipc/mach_debug.c (host_ipc_hash_info): quiet GCC warning about uninitialized variable, Marin Ramesa, 2013/12/18
- Re: [PATCH 2/3] ipc/mach_debug.c (host_ipc_hash_info): quiet GCC warning about uninitialized variable,
Richard Braun <=
- [PATCH 3/3] vm/vm_debug.c: quiet GCC warning about uninitialized variable, Marin Ramesa, 2013/12/18
- Re: [PATCH 1/3] ipc: avoid dereference of null pointer and quiet the GCC warning about uninitialized variable, Anatoly A. Kazantsev, 2013/12/18
- Re: [PATCH 1/3] ipc: avoid dereference of null pointer and quiet the GCC warning about uninitialized variable, Marin Ramesa, 2013/12/18
- Re: [PATCH 1/3] ipc: avoid dereference of null pointer and quiet the GCC warning about uninitialized variable, Richard Braun, 2013/12/18
- Re: [PATCH 1/3] ipc: avoid dereference of null pointer and quiet the GCC warning about uninitialized variable, Richard Braun, 2013/12/18
- Re: [PATCH 1/3] ipc: avoid dereference of null pointer and quiet the GCC warning about uninitialized variable, Marin Ramesa, 2013/12/18
- Re: [PATCH 1/3] ipc: avoid dereference of null pointer and quiet the GCC warning about uninitialized variable, Marin Ramesa, 2013/12/18
- Re: [PATCH 1/3] ipc: avoid dereference of null pointer and quiet the GCC warning about uninitialized variable, Richard Braun, 2013/12/18
- Re: [PATCH 1/3] ipc: avoid dereference of null pointer and quiet the GCC warning about uninitialized variable, Marin Ramesa, 2013/12/18