From patchwork Wed Aug 14 08:16:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 1972238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Uc8KfCe0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WkLhQ08vTz1yYl for ; Wed, 14 Aug 2024 18:17:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C122C3858404 for ; Wed, 14 Aug 2024 08:17:07 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id CFC033858401 for ; Wed, 14 Aug 2024 08:16:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CFC033858401 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CFC033858401 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723623405; cv=none; b=NuFN2Wf4bzjjUu0/9AUis1I/VJEcSC1bNVSNmTcH7dPRzV7FSk6MYXm84CAmPj19ewXAFt592pyXhOhW710WzXkXfkb1OpzxmdPl1uWA+H5YqLOoPMOIEenJ1dk3dcA8mKo7KEzPZ/15/Uzh1SIJy8uzSlO0tJkmXrfRmReqB34= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723623405; c=relaxed/simple; bh=k1bYs3J2jKJDWCH4lSnRYgIzfYSkc0gU3gH9BINCVbc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Rn0HWnm66sdpCYTYOxXd/6M6/qs6RaqJ/fPfIr5c1SUkhBDG787y8b5kwE2C3oyIrl64eZEyrq9epqFw20dSQrtS7dX0C7n3Ov3wZDz8fnMgovSerbkCqY+ur6BHQ5JayS6nXtSTSwo2xZVmKEJzxWXWpJ+GR1WgwG7soRWA/58= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723623394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YNWEuoPoTxa4fqTrcjoUIxZIKFItbUv8AkdNik9GclM=; b=Uc8KfCe09nMwudbsOYoOJyaYYjfo9JT+hFEOWTYBK7mR7pHcYMi1lGxoAqJ8NfmYgSck7v /+KEus7koxVUJnYH15usDJYKtOKbXawpX/KzRDYealmry71tSR7iX2n3wcA6/FgURUS2vT mkwud0AZ8zisphAvBvAhswnxBmrqbJk= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-467-rur-_ifoOiCQdM7JB0mhfA-1; Wed, 14 Aug 2024 04:16:32 -0400 X-MC-Unique: rur-_ifoOiCQdM7JB0mhfA-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 27B8D19541A9 for ; Wed, 14 Aug 2024 08:16:32 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.71]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6B66A300019C for ; Wed, 14 Aug 2024 08:16:29 +0000 (UTC) From: =?utf-8?b?RnLDqWTDqXJpYyBCw6lyYXQ=?= To: libc-alpha@sourceware.org Subject: [PATCH] libio/tst-getdelim: Add new test covering NUL as a delimiter Date: Wed, 14 Aug 2024 10:16:25 +0200 Message-ID: <20240814081625.453536-1-fberat@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org Hello, This patch adds new tests to tst-getdelim to cover the case where '\0' is set as delimiter. This should cover the missing test not covered by tst-getline available for review: https://inbox.sourceware.org/libc-alpha/4c39a1af-f4c4-683d-13d4-88c3abe8e3@redhat.com/T/#t I'm skipping swbz#28038 based on the discussion around getline. Fred. Subject: [PATCH] libio/tst-getdelim: Add new test covering NUL as a delimiter Add a new test to getdelim to verify that '\0' can be set as a delimiter. --- libio/tst-getdelim.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/libio/tst-getdelim.c b/libio/tst-getdelim.c index e6dd964b49..709996c204 100644 --- a/libio/tst-getdelim.c +++ b/libio/tst-getdelim.c @@ -1,4 +1,6 @@ -/* Check that getdelim sets error indicator on error (BZ #29917) +/* Test getdelim conforming to POSIX specifications. + + Note: Most getdelim use cases are covered by stdio-common/tst-getline. Copyright (C) 2023-2024 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -18,18 +20,36 @@ . */ #include +#include #include #include +#include +#include static int do_test (void) { + /* Check that getdelim sets error indicator on error (BZ #29917) */ clearerr (stdin); TEST_VERIFY (getdelim (0, 0, '\n', stdin) == -1); TEST_VERIFY (ferror (stdin) != 0); TEST_VERIFY (errno == EINVAL); + /* Test getdelim with NUL as delimiter */ + verbose_printf ("Testing NUL delimiter\n"); + char *lineptr = NULL; + size_t linelen = 0; + char membuf[] = "abc\0d\nef\0"; + FILE *memstream = fmemopen(membuf, sizeof(membuf), "r"); + TEST_VERIFY_EXIT (memstream != NULL); + TEST_VERIFY (getdelim (&lineptr, &linelen, '\0', memstream) != -1); + TEST_COMPARE_BLOB (lineptr, 4, "abc\0", 4); + TEST_VERIFY (getdelim (&lineptr, &linelen, '\0', memstream) != -1); + TEST_COMPARE_BLOB (lineptr, 5, "d\nef\0", 5); + fclose (memstream); + free (lineptr); + return 0; }