bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fchdir() question


From: Bruno Haible
Subject: Re: fchdir() question
Date: Wed, 08 Aug 2018 11:39:47 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-130-generic; KDE/5.18.0; x86_64; ; )

Barath Aron wrote:
> What system implements a realloc() which does not work 
> if ptr is null pointer?

None, according to our findings [1].

> I looked into the fchdir.c ...
      new_dirs =
        (dirs != NULL
         ? (dir_info_t *) realloc (dirs, new_allocated * sizeof *dirs)
         : (dir_info_t *) malloc (new_allocated * sizeof *dirs));
> To me, it looks the ternary is unnecessary there, and only a single 
> realloc() is fine.

This is correct.

However, I prefer to keep the code as it is. Given that everyone knows
what malloc() does, whereas
  - For realloc, there are three cases,
  - You have to look up the documentation to know exactly how realloc()
    behaves in each of the cases,
the code is simpler to understand as is.

> Or this is really a bug?

It's not a bug. It's a question of style.

Bruno

[1] https://www.gnu.org/software/gnulib/manual/html_node/realloc.html




reply via email to

[Prev in Thread] Current Thread [Next in Thread]