# realloc

2 messages from 2006-04-07 to 2006-04-07. Participants: Morten Welinder, Junio C Hamano.
Thread: https://gitlist.dev/t/3822

## Morten Welinder, 2006-04-07 20:11

Subject: realloc
Message-ID: <118833cc0604071311v1da93f83n112cc2ea44552ca9@mail.gmail.com>
URL: https://gitlist.dev/e/118833cc0604071311v1da93f83n112cc2ea44552ca9%40mail.gmail.com

```
I could be wrong, but shouldn't

      var = realloc (var, whatever);

be changed to call xrealloc?  That, or assign to a different variable and check
for NULL.

This should affect the last four hits below.

M.




/scratch/welinder/git> grep -w realloc *.c
daemon.c:               newlist = realloc(socklist, sizeof(int) *
(socknum + 1));
diff-delta.c:                           out = realloc(out, outsize);
git.c:          cmdname = realloc(cmdname, cmdname_alloc * sizeof(*cmdname));
ls-files.c:             which->excludes = realloc(which->excludes,
sha1_file.c:                            buf = realloc(buf, size);

```

## Junio C Hamano, 2006-04-07 20:35

Subject: Re: realloc
Message-ID: <7vmzexi0od.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vmzexi0od.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <118833cc0604071311v1da93f83n112cc2ea44552ca9@mail.gmail.com>

```
"Morten Welinder" <mwelinder@gmail.com> writes:

> I could be wrong, but shouldn't
>
>       var = realloc (var, whatever);
>
> be changed to call xrealloc?  That, or assign to a different variable and check
> for NULL.
>
> This should affect the last four hits below.
>
> M.
>
>
>
>
> /scratch/welinder/git> grep -w realloc *.c
> daemon.c:               newlist = realloc(socklist, sizeof(int) *
> (socknum + 1));
> diff-delta.c:                           out = realloc(out, outsize);
> git.c:          cmdname = realloc(cmdname, cmdname_alloc * sizeof(*cmdname));
> ls-files.c:             which->excludes = realloc(which->excludes,
> sha1_file.c:                            buf = realloc(buf, size);

There is no excuse for not using xrealloc() in git.c,
ls-files.c, and sha1_file.c.

The diff-delta.c code wants to be independent from the rest of
git code, so it probably should check the returned value itself.

Historically to a certain degree daemon.c also wanted to be
independent from the rest of git, but I suspect it still is the
case (it uses small pieces from packet interface but that is
about it).

```
