public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	libc-alpha@sourceware.org,
	"Andreas K . Huettel" <dilfridge@gentoo.org>,
	Florian Weimer <fweimer@redhat.com>
Subject: Re: [PATCH v6 3/3] linux: Set internal DIR filepos as off64_t (BZ #23960, BZ #24050)
Date: Fri, 10 Mar 2023 13:41:15 -0800	[thread overview]
Message-ID: <75761f49-474e-6c3c-7029-03b30e83da3e@cs.ucla.edu> (raw)
In-Reply-To: <20230302145732.2293756-4-adhemerval.zanella@linaro.org>

On 2023-03-02 06:57, Adhemerval Zanella wrote:
> +      for (i = 0; i < dirstream_loc_size (&dirp->locs); i++)
> +	if (*dirstream_loc_at (&dirp->locs, i) == dirp->filepos)
> +	  break;
> +      /* It should be pre-allocated on readdir.  */
> +      assert (i != dirstream_loc_size (&dirp->locs));

This should be something like the following, to avoid unnecessary work 
when assertions are disabled:

   for (long int i = 0; ; i++)
     {
       assert (i < dirstream_loc_size (&dirp->locs));
       if (*dirstream_loc_at (&dirp->locs, i) == dirp->filepos)
	break;
     }

> +      /* This assignment might overflow, however most likely ENOME would
> +	 happen long before.  */
> +      dsp.p.info = i;

This doesn't sound right. The allocator should never create a table with 
more than LONG_MAX entries because the upper part of any such table 
would be useless. If that is done right, the assignment cannot overflow.

> +_Static_assert (sizeof (long int) == sizeof (off64_t),
> +		"sizeof (long int) != sizeof (off64_t)");

This is confusing. First, we need require only that long int be at least 
as wide as off64_t; it doesn't have to be exactly the same width. 
Second, why both "==" and "!="? Third, why not use plain "static_assert" 
with one arg instead of the old-fashioned "_Static_assert" with two? We 
can support this form of static_assert on older compilers - see how 
Gnulib does it.


> +static __always_inline bool
> +telldir_need_dirstream (__off64_t d_off)
> +{
> +  return d_off >= 1UL << 31;
> +}

Safer would be '! (TYPE_MINIMUM (off_t) <= d_off && d_off <= 
TYPE_MAXIMUM (off_t))', in case d_off is negative (or off_t isn't 32-bit 
:-).

  reply	other threads:[~2023-03-10 21:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02 14:57 [PATCH v6 0/3] Fix opendir regression on some FS Adhemerval Zanella
2023-03-02 14:57 ` [PATCH v6 1/3] linux: Use getdents64 on non-LFS readdir Adhemerval Zanella
2023-03-02 14:57 ` [PATCH v6 2/3] support: Add xreallocarray Adhemerval Zanella
2023-03-10 16:49   ` Florian Weimer
2023-03-10 18:44     ` Adhemerval Zanella Netto
2023-03-10 21:21       ` Paul Eggert
2023-03-02 14:57 ` [PATCH v6 3/3] linux: Set internal DIR filepos as off64_t (BZ #23960, BZ #24050) Adhemerval Zanella
2023-03-10 21:41   ` Paul Eggert [this message]
2023-03-13 12:40     ` Adhemerval Zanella Netto
2023-03-13 12:45       ` Adhemerval Zanella Netto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=75761f49-474e-6c3c-7029-03b30e83da3e@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=adhemerval.zanella@linaro.org \
    --cc=dilfridge@gentoo.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).