Deutsch   English   Français   Italiano  
<slrnvce8vt.l93.ike@iceland.freeshell.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Ike Naar <ike@sdf.org>
Newsgroups: comp.lang.c
Subject: Re: valgrind leak I can't find
Date: Thu, 22 Aug 2024 11:41:50 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <slrnvce8vt.l93.ike@iceland.freeshell.org>
References: <j8idnQlHTPZXZFv7nZ2dnZfqn_GdnZ2d@brightview.co.uk>
Injection-Date: Thu, 22 Aug 2024 13:41:50 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3cf8d2f740ec50d350419ecde0d54117";
	logging-data="452470"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/O+Qh7OpBILSTUCNmZX34B"
User-Agent: slrn/1.0.3 (Patched for libcanlock3) (NetBSD)
Cancel-Lock: sha1:Xlw6JXDhZOr4UD5TjFke/Wxsc7s=
Bytes: 1632

On 2024-08-22, Mark Summerfield <mark@qtrac.eu> wrote:
> Here is the vec_str_insert() function:
>
> void vec_str_insert(VecStr* vec, int index, char* value) {
>     assert_notnull(vec);
>     assert_notnull(value);
>     if (index == vec->_size) { // add at the end
>         vec_str_push(vec, value);
>         return;
>     }
>     assert_valid_index(vec, index);
>     if (vec->_size == vec->_cap)
>         vec_str_grow(vec);
>     for (int i = vec->_size; i > index; --i)
>         vec->_values[i] = vec->_values[i - 1];
>     vec->_values[index] = value;
>     vec->_size++;
> }

Just out of curiosity, why have special code (the vec_str_push part)
for the case index == vec->_size, when the general code (grow, for loop etc.)
would work just fine for that case?