From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by sourceware.org (Postfix) with ESMTPS id EDFC73858C27 for ; Tue, 19 Oct 2021 06:23:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EDFC73858C27 Received: by mail-yb1-xb2c.google.com with SMTP id r184so1936517ybc.10 for ; Mon, 18 Oct 2021 23:23:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KhbkZAGZjYWg6bk3o9oLKAQQSu/y/n5c/QHROxinPPA=; b=XPgGd5efgqSowL4Y+5WDu4tFKQaYZCU3okPSPQqENCUtIohAs+A95G/KO53d0WwMaH kuQL0BGnMLbvzM7lU3xuX6NSdeDIobb5ew/LXWuG/5SsxRWnxaRapsotPTsS5pzEKpEC ARR6yovvFEk5hXqevpYMK2JzM7renM6/iIx0N5Ida6PUpUL6hv/Daxz7yC9UtP6qKUtU byTlVOfOAx8/6iYOoY2D3wvW8tTA+DBNN6xrCJdirl1YnVTMf9kSuzT+foViZWu0R9KV RGhX6kOs+TX1vNfwpQ3r+0U1flDZUjeVq52nqefi2UlWC/N6WJbq5H26fNwyNDAuOECM TSqQ== X-Gm-Message-State: AOAM532+znnpckIA5b8/1p8m04o8jz0JROvjHeKuHGV7vmUypfQjax8z EQDyGA5rCgQDEvZTr01WS3Qw8pwVwEiAYIEMXgT89Q== X-Google-Smtp-Source: ABdhPJwjf9ahQU+FH1JrsrFz3/awh0jafJRygPzQVrjKwOh1GJfjXd0eiXeAZeUdENvbFyL2YHwOAAY3Flcxtz8vpqM= X-Received: by 2002:a25:9748:: with SMTP id h8mr4269344ybo.111.1634624601450; Mon, 18 Oct 2021 23:23:21 -0700 (PDT) MIME-Version: 1.0 References: <20211008004643.532196-1-maskray@google.com> <87lf2uyip5.fsf@mid.deneb.enyo.de> In-Reply-To: <87lf2uyip5.fsf@mid.deneb.enyo.de> From: =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= Date: Mon, 18 Oct 2021 23:23:10 -0700 Message-ID: Subject: Re: [PATCH v2] linux: Fix a non-constant expression in _Static_assert To: Florian Weimer Cc: Fangrui Song via Libc-alpha , Adhemerval Zanella Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-24.0 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Oct 2021 06:23:23 -0000 On Thu, Oct 14, 2021 at 10:19 PM Florian Weimer wrote: > > * Fangrui Song via Libc-alpha: > > > diff --git a/sysdeps/unix/sysv/linux/opendir.c b/sysdeps/unix/sysv/linux/opendir.c > > index 48f254d169..88640f44ee 100644 > > --- a/sysdeps/unix/sysv/linux/opendir.c > > +++ b/sysdeps/unix/sysv/linux/opendir.c > > @@ -103,7 +103,7 @@ __alloc_dir (int fd, bool close_fd, int flags, > > file system provides a bogus value. */ > > enum { max_buffer_size = 1048576 }; > > > > - const size_t allocation_size = 32768; > > + enum { allocation_size = 32768 }; > > _Static_assert (allocation_size >= sizeof (struct dirent64), > > "allocation_size < sizeof (struct dirent64)"); > > Below we have: > > /* Increase allocation if requested, but not if the value appears to > be bogus. It will be between 32Kb and 1Mb. */ > size_t allocation = MIN (MAX ((size_t) statp->st_blksize, allocation_size), > max_buffer_size); > > Mixed-type MAX is a bit iffy, but we already have mixed-type MIN here, > so it probably does not matter. I'll wait few days and push this form: - size_t allocation = MIN (MAX ((size_t) statp->st_blksize, allocation_size), - max_buffer_size); + size_t allocation = MIN (MAX ((size_t) statp->st_blksize, (size_t) + allocation_size), (size_t) max_buffer_size);