On Wed, Nov 10, 2021 at 6:56 PM Richard W.M. Jones <rjones(a)redhat.com> wrote:
On Wed, Nov 10, 2021 at 06:00:17PM +0200, Nir Soffer wrote:
> - Indent the pseudo code to separate it from the comment text
> - Add missing blank line after return to make the flow more clear
>
> Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
> ---
> common/utils/vector.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/common/utils/vector.c b/common/utils/vector.c
> index b145e7d..550e624 100644
> --- a/common/utils/vector.c
> +++ b/common/utils/vector.c
> @@ -46,8 +46,8 @@ generic_vector_reserve (struct generic_vector *v, size_t n, size_t
itemsize)
> size_t reqcap, reqbytes, newcap, newbytes, t;
>
> /* New capacity requested. We must allocate this minimum (or fail).
> - * reqcap = v->cap + n
> - * reqbytes = reqcap * itemsize
> + * reqcap = v->cap + n
> + * reqbytes = reqcap * itemsize
> */
> if (ADD_SIZE_T_OVERFLOW (v->cap, n, &reqcap) ||
> MUL_SIZE_T_OVERFLOW (reqcap, itemsize, &reqbytes)) {
> @@ -57,8 +57,8 @@ generic_vector_reserve (struct generic_vector *v, size_t n, size_t
itemsize)
>
> /* However for the sake of optimization, scale buffer by 3/2 so that
> * repeated reservations don't call realloc often.
> - * newcap = v->cap + (v->cap + 1) / 2
> - * newbytes = newcap * itemsize
> + * newcap = v->cap + (v->cap + 1) / 2
> + * newbytes = newcap * itemsize
> */
> if (ADD_SIZE_T_OVERFLOW (v->cap, 1, &t) ||
> ADD_SIZE_T_OVERFLOW (v->cap, t/2, &newcap) ||
> @@ -74,6 +74,7 @@ generic_vector_reserve (struct generic_vector *v, size_t n, size_t
itemsize)
> newptr = realloc (v->ptr, newbytes);
> if (newptr == NULL)
> return -1;
> +
> v->ptr = newptr;
> v->cap = newcap;
> return 0;
ACK, thanks
Pushed as 2b588bdee8e00a57f8410ec44f9ac6d0d8c7cdb3
I'll push the same change to nbdkit.