From patchwork Wed Dec 30 20:15:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 41604 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6BB06388C026; Wed, 30 Dec 2020 20:15:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6BB06388C026 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609359320; bh=865jMgKztixWfbcfWMdN64MmWy8TSyjzP5w906qiAeY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Ijmx3GgqIXsDnM/nQVp8waqx+VGgox8OZ29m9Zyb0Tg+5K8UXh3Xf+PFhq7gOE2Rw KTUeIdEUw82cccEUzMOG4KoXQW5x/X0a0qo966db5p+JtrE8f4ta6fNhXcQJCUQ4W6 1lVZO+be+eMznB6heGH3TUAO20S0kWGBGYG28Vmw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by sourceware.org (Postfix) with ESMTPS id 66070388C017 for ; Wed, 30 Dec 2020 20:15:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 66070388C017 Received: by mail-qk1-x72a.google.com with SMTP id f26so14917190qka.0 for ; Wed, 30 Dec 2020 12:15:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=865jMgKztixWfbcfWMdN64MmWy8TSyjzP5w906qiAeY=; b=oziH+j9so5d7601hmaNpXgTcbKT3OUBP6T2QuB1belVNWUjS0+t5+zM4sd4w/LcJUw TeZc7s79ZyudZxxHCDxMG9LKY/nFvOFdQ5T5KAC4/NU5OJXWKDAOkG/dzycNb9RH02I/ 4Uh/KKmliDhswxjKeKmU/bWLsNTzSgg3KwbHFHhGhzBiokFiS0JetPsUAChiARLqDKB2 YNkQBzsVKbX1Qe1AhSgr5/fI7oGio+gOPI1FW9iYwAvmsktxLC8qM8pFZKNA+zR+nFma rU1pjyoV0ujEqV368IuC38i/gqQihv6nalyk6jIxJT6esYvsjPaLPsZcE5GYLmJz965c cjZw== X-Gm-Message-State: AOAM532Ls8rPr0BesGgpugno4aoxwLzqgmWKb/uG37lIw7MFY3Wg3IAz eB76jl1R1s36GK04KhJi5me9U4mm1yN41Q== X-Google-Smtp-Source: ABdhPJwuKYo40Sw3ypvw30oO52izNm8WLp4gZ0HJlTQWJeHvTuYzLC5Ym5qH2xIfmRUPYDlGRva/XA== X-Received: by 2002:a37:9505:: with SMTP id x5mr50646293qkd.295.1609359317714; Wed, 30 Dec 2020 12:15:17 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v145sm5949057qka.27.2020.12.30.12.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 12:15:17 -0800 (PST) To: libc-alpha@sourceware.org, Paul Eggert Subject: [PATCH 4/5] Sync flexmember.h with gnulib Date: Wed, 30 Dec 2020 17:15:06 -0300 Message-Id: <20201230201507.2755086-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201230201507.2755086-1-adhemerval.zanella@linaro.org> References: <20201230201507.2755086-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Cc: bug-gnulib@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" It sync with gnulib commit 43ee1a6bf. --- posix/flexmember.h | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/posix/flexmember.h b/posix/flexmember.h index 30e6a6b867..1e839f08c2 100644 --- a/posix/flexmember.h +++ b/posix/flexmember.h @@ -33,11 +33,26 @@ # define FLEXALIGNOF(type) _Alignof (type) #endif -/* Upper bound on the size of a struct of type TYPE with a flexible - array member named MEMBER that is followed by N bytes of other data. - This is not simply sizeof (TYPE) + N, since it may require - alignment on unusually picky C11 platforms, and - FLEXIBLE_ARRAY_MEMBER may be 1 on pre-C11 platforms. +/* Yield a properly aligned upper bound on the size of a struct of + type TYPE with a flexible array member named MEMBER that is + followed by N bytes of other data. The result is suitable as an + argument to malloc. For example: + + struct s { int n; char d[FLEXIBLE_ARRAY_MEMBER]; }; + struct s *p = malloc (FLEXSIZEOF (struct s, d, n * sizeof (char))); + + FLEXSIZEOF (TYPE, MEMBER, N) is not simply (sizeof (TYPE) + N), + since FLEXIBLE_ARRAY_MEMBER may be 1 on pre-C11 platforms. Nor is + it simply (offsetof (TYPE, MEMBER) + N), as that might yield a size + that causes malloc to yield a pointer that is not properly aligned + for TYPE; for example, if sizeof (int) == alignof (int) == 4, + malloc (offsetof (struct s, d) + 3 * sizeof (char)) is equivalent + to malloc (7) and might yield a pointer that is not a multiple of 4 + (which means the pointer is not properly aligned for struct s), + whereas malloc (FLEXSIZEOF (struct s, d, 3 * sizeof (char))) is + equivalent to malloc (8) and must yield a pointer that is a + multiple of 4. + Yield a value less than N if and only if arithmetic overflow occurs. */ #define FLEXSIZEOF(type, member, n) \