From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by sourceware.org (Postfix) with ESMTPS id EEAD93858D28 for ; Tue, 8 Feb 2022 21:25:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EEAD93858D28 Received: by mail-io1-xd2d.google.com with SMTP id e79so675895iof.13 for ; Tue, 08 Feb 2022 13:25:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UosPFsJpHs2ws2V+swhw/RqGJUlo9Ir/x8UPPUn9Ges=; b=Z6r9W6E+LNef2ay+keWkRtXhbnSNSPA/vn3HyE7u5fI/bMWf89Y4AAMU/ZtI9lSp5X DabOhPx0gY4U2C9DRSKAm0ncCtecLciWoqEJtmOEc4dChfGIL44npVm50aMP2LHJ4RRZ 7YaxZgyBvT3H0TeQHHG2oOVCflUoTU9IItpo3dveL2LQjg/jYterPGJltAMb2EvHXBiu P/mWmvuNuBehCwsAqKvoRCbUMWPFJti3iYqy+ut2IFgd7yDwxoUBon7FPXvgopkOQ2VV nwTNsg+P7vj4kUQoRQNXCoTdDC2uXUYPLoT7COAtYwLrdLSPpywqBEuRTH0JokUBteYG 9gcA== X-Gm-Message-State: AOAM532rqidCvdTT7SMGWt593gnb+cayDncmaNJ4Kk5r7FhlBDbprEm9 N8A2a3x+axppwGoMUBH7sTPXLD8Ah48= X-Google-Smtp-Source: ABdhPJw7SX8yJvj8MQPx9jO94LXFZ+N0LG7zp1WPygTg1zwx87YrEEMdDyaAJ4lw7fP2qO3HuseBXw== X-Received: by 2002:a05:6638:114:: with SMTP id x20mr2869996jao.158.1644355504996; Tue, 08 Feb 2022 13:25:04 -0800 (PST) Received: from localhost.localdomain (node-17-161.flex.volo.net. [76.191.17.161]) by smtp.googlemail.com with ESMTPSA id p5sm289005ilo.37.2022.02.08.13.25.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:25:04 -0800 (PST) From: Noah Goldstein To: libc-alpha@sourceware.org Subject: [PATCH v3] String: Ensure 'MIN_PAGE_SIZE' is multiple of 'getpagesize' Date: Tue, 8 Feb 2022 15:24:59 -0600 Message-Id: <20220208212459.3526397-1-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220207201624.601598-1-goldstein.w.n@gmail.com> References: <20220207201624.601598-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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, 08 Feb 2022 21:25:07 -0000 When 'TEST_LEN' was defined as (4096 * 3) the allocation size Would not be a multiple of system page size if system page size > 4096. --- string/test-strcmp.c | 14 +++++++------- string/test-strncmp.c | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/string/test-strcmp.c b/string/test-strcmp.c index eacbdc8857..0abce769d0 100644 --- a/string/test-strcmp.c +++ b/string/test-strcmp.c @@ -16,7 +16,7 @@ License along with the GNU C Library; if not, see . */ -#define TEST_LEN (4096 * 3) +#define TEST_LEN (getpagesize () * 3) #define MIN_PAGE_SIZE (TEST_LEN + 2 * getpagesize ()) #define TEST_MAIN @@ -393,7 +393,7 @@ int test_main (void) { size_t i, j; - + const size_t test_len = MIN(TEST_LEN, 3 * 4096); test_init (); check(); check2 (); @@ -435,7 +435,7 @@ test_main (void) for (j = 0; j < 160; ++j) { - for (i = 0; i < TEST_LEN;) + for (i = 0; i < test_len;) { do_test (getpagesize () - j - 1, 0, i, 127, 0); do_test (getpagesize () - j - 1, 0, i, 127, 1); @@ -461,17 +461,17 @@ test_main (void) { i += 7; } - else if (i + 161 < TEST_LEN) + else if (i + 161 < test_len) { i += 31; i *= 17; i /= 16; - if (i + 161 > TEST_LEN) + if (i + 161 > test_len) { - i = TEST_LEN - 160; + i = test_len - 160; } } - else if (i + 32 < TEST_LEN) + else if (i + 32 < test_len) { i += 7; } diff --git a/string/test-strncmp.c b/string/test-strncmp.c index 1a3cee1792..831cb77893 100644 --- a/string/test-strncmp.c +++ b/string/test-strncmp.c @@ -16,7 +16,7 @@ License along with the GNU C Library; if not, see . */ -#define TEST_LEN (4096 * 3) +#define TEST_LEN (getpagesize () * 3) #define MIN_PAGE_SIZE (TEST_LEN + 2 * getpagesize ()) #define TEST_MAIN @@ -430,7 +430,7 @@ check_overflow (void) const size_t of_masks[] = { ULONG_MAX, LONG_MIN, ULONG_MAX - (ULONG_MAX >> 2), ((size_t)LONG_MAX) >> 1 }; - + const size_t test_len = MIN(TEST_LEN, 3 * 4096); for (of_idx = 0; of_idx < sizeof (of_masks) / sizeof (of_masks[0]); ++of_idx) { of_mask = of_masks[of_idx]; @@ -484,7 +484,7 @@ check_overflow (void) of_mask - j * 2, 0, 127, -1); } - for (i = 1; i < TEST_LEN; i += i) + for (i = 1; i < test_len; i += i) { do_test_n (j, 0, i - 1, of_mask, 0, 127, 0); do_test_n (j, 0, i - 1, of_mask, 0, 127, 1); @@ -540,7 +540,7 @@ int test_main (void) { size_t i, j; - + const size_t test_len = MIN(TEST_LEN, 3 * 4096); test_init (); check1 (); @@ -608,7 +608,7 @@ test_main (void) for (j = 0; j < 160; ++j) { - for (i = 0; i < TEST_LEN;) + for (i = 0; i < test_len;) { do_test_n (getpagesize () - j - 1, 0, i, i + 1, 0, 127, 0); do_test_n (getpagesize () - j - 1, 0, i, i + 1, 0, 127, 1); @@ -677,17 +677,17 @@ test_main (void) { i += 7; } - else if (i + 161 < TEST_LEN) + else if (i + 161 < test_len) { i += 31; i *= 17; i /= 16; - if (i + 161 > TEST_LEN) + if (i + 161 > test_len) { - i = TEST_LEN - 160; + i = test_len - 160; } } - else if (i + 32 < TEST_LEN) + else if (i + 32 < test_len) { i += 7; } -- 2.25.1