From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 75E2E1F934 for ; Wed, 30 Dec 2020 20:15:24 +0000 (UTC) Received: from localhost ([::1]:50124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kuhsR-0002l2-Kl for normalperson@yhbt.net; Wed, 30 Dec 2020 15:15:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kuhsO-0002jx-9U for bug-gnulib@gnu.org; Wed, 30 Dec 2020 15:15:20 -0500 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]:39227) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kuhsM-0001pr-NC for bug-gnulib@gnu.org; Wed, 30 Dec 2020 15:15:20 -0500 Received: by mail-qk1-x72f.google.com with SMTP id p14so14869934qke.6 for ; Wed, 30 Dec 2020 12:15:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=865jMgKztixWfbcfWMdN64MmWy8TSyjzP5w906qiAeY=; b=kiggoEj0ZZ2qt1W04EWhDRsQDJentjqkYDU8kaITn67NphU9SSeByzqXjK9TwchMD+ Tuzgc6q98U4El1llIovR90qK734lgqT1F1Z44UpdD0J1mg79sZkrRmwwujTbrKHRviXb IXgLaDsE/IUeL69Dw5YoYD/Deil1+qtygF9yue4fdMuTO8YxbUwTBKvVYJGIJDH+VWho TsLugA98dfWqRxVjNOb6830aoDUq2jFEVx2c1X530SjF66Wn0p5UGsNzxhKeFRmgBSOj cQMkDZsQIYLEB80iRuOXn9iKjSIzpoUu2FiI/ELvcEl0gfXpz3oFGRC2w3i6NvllJelR LkXQ== 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=ZgmvxwU9uphDU4V2OmRIGGpB5yptmeTyiJK1NPZIACpvTVTeIYl81PEt9zlK/mL+/1 sZ1REyxmQ7GUl3Hc0Gt+obNTny8Oz/rnpcjjKML9NtBe+ADtobZoYg+b8TzMtPRPjQwr Hxqh7pVhOYON+j9qTtjz5J6G5aHNsVw2l6cR5WE4lBNBivLOc7xOI2oSSAubadpesgU5 +z5KSE0bDFdBwipD8bHDjh9UmTIYudK4duFtpwbhQQXLk5eYGsqekzL8b2hCKlL9v3+Y XxumxMYBvqyeB82ugRcpNJR3tsOlowOE1MHOGptaI4ElJ81Zerr7GJvPeyTRBNhvR5YV LPyQ== X-Gm-Message-State: AOAM530cSoJP0S2ISt0yaMgx4Gtqmrn/Neg9LXmHUcW10wNI7hqfH6Xb cfHjRr+WTWDVv8x0rOusn+CwNg== 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) From: Adhemerval Zanella 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 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::72f; envelope-from=adhemerval.zanella@linaro.org; helo=mail-qk1-x72f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bug-gnulib@gnu.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" 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) \ -- 2.25.1