Download raw body.
histedit_parse_list: avoid needless free(line)
On 2023/02/27 10:25:55 +0100, Omar Polo <op@omarpolo.com> wrote:
> On 2023/02/27 09:27:51 +0100, Theo Buehler <tb@theobuehler.org> wrote:
> > On Mon, Feb 27, 2023 at 09:10:49AM +0100, Omar Polo wrote:
> > > Don't need to free(line) at every iteration, getline(3) allows to
> > > re-use the storage safely (since it tracks linesize too.) It
> > > simplifies a bit the code.
> > >
> > > ok?
> >
> > Yes, ok.
> >
> > I think size should be initialized to 0 at the top of the function - our
> > getline does the right thing if *lineptr is NULL, but the manual says
> >
> > If *n is non-zero, then *lineptr must be pre-allocated to at least *n
> > bytes.
>
> Oops, missed that size (now linesize) was left un-initialized.
>
> > Also, maybe call it linesize instead of size like in all other getline()
> > calls in this giant file.
>
> I've committed with your suggestion, thanks!
>
> This prompted me to go back and re-check the various getline() calls.
> All of them seems fine (both line and linesize initialized to 0/NULL)
> except for one in diff3.c:
...i've seen too many getline() calls today... of course i meant this
instead of the previous diff
diff /home/op/w/got
commit - e96d39bf87c8025d794e9c5c5bfcbbca58c216ac
path + /home/op/w/got
blob - ff8cf0b4e609ae11ccb229f749a19390a8a22563
file + lib/diff3.c
--- lib/diff3.c
+++ lib/diff3.c
@@ -688,17 +688,17 @@ get_line(char **ret, FILE *b, size_t *n, struct diff3_
return NULL;
}
static const struct got_error *
get_line(char **ret, FILE *b, size_t *n, struct diff3_state *d3s)
{
const struct got_error *err = NULL;
char *cp = NULL;
- size_t size;
+ size_t size = 0;
ssize_t len;
char *new;
*ret = NULL;
if (n != NULL)
*n = 0;
len = getline(&cp, &size, b);
histedit_parse_list: avoid needless free(line)