From patchwork Wed Jul 15 14:44:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 7691 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com Received: (qmail 114943 invoked by alias); 15 Jul 2015 14:44:23 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 114934 invoked by uid 89); 15 Jul 2015 14:44:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-yk0-f178.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=5G5tY5M5g7zKsEwPGLmNL89cn9dAaRctwCX+9X8nnrI=; b=CHCPKph0GeegNI7QGC1NQSmZWKPSKpXGkVRSPVMm5z8YdW4rRAS8lhNcjsNHtRJCg+ f6ssHP+g91pnmsZNHneoYOXreA+rtyUV4s7hP9WsHrzSMVuz+29euQQvreKdJv5237BQ tJjuc6TKlX8nL/rNehys/+EuiKdQ2Q/3Rfbo9Z9fy2cz0gKnFlYaEUO5jCQy0/fUNQSu hL8/Pe0EtiD8eVPXeal04T90CukMurcBiYaDMbXFw7ipWP4w5SBeZ9gG1cvdTcGbe2Us LUVp/tywecvLzf0PhENEfoI0FTzj8P6toRRpC1tWsH4LLr+TJGeYkGGD6RlbITyjgkx8 psSw== X-Gm-Message-State: ALoCoQn8C6QYtO15Vir8hhxExcV5CWC7i31xODVzXyz++zzPJQOdpzSfiJ9jJonxmwhdXoeMlEd2 X-Received: by 10.170.157.87 with SMTP id y84mr4398559ykc.28.1436971458896; Wed, 15 Jul 2015 07:44:18 -0700 (PDT) Message-ID: <55A671BE.6090306@linaro.org> Date: Wed, 15 Jul 2015 11:44:14 -0300 From: Adhemerval Zanella User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: libc-alpha@sourceware.org CC: Carlos O'Donell Subject: Re: [PATCH 2/2] libio: Update tst-fmemopen2.c References: <55802AFD.1040404@linaro.org> <559C2D12.6000508@redhat.com> <559C4341.3040107@linaro.org> <55A66422.5010306@linux.vnet.ibm.com> In-Reply-To: <55A66422.5010306@linux.vnet.ibm.com> Hi Stefan, Thanks for checking it. On 15-07-2015 10:46, Stefan Liebler wrote: > Hi, > > i get the following failure for this test on s390-32: > FAIL: third ftello returned 28, expected 100 > FAIL: final string is "just hellod`<80>@^]<92>Ua^C^?<9E>u^?<9E>u`", expected "just hellod" > > I think the "expected 100" should be "expected 11". See testcode - there is nbuf instead of nstr as argument to printf: > if (o != nstr) > { > printf ("FAIL: third ftello returned %jd, expected %zu\n", > (intmax_t)o, nbuf); > result = 1; > } > > [...] > > Is this is a bug in the new fmemopen implementation?! > If it isn't, the testcase should initialize buf with zeros. Yes, it is an issue with new implementation since it requires to open the stream to first null byte (thus the strnlen) only for 'a' mode. The follow patch should fix the behaviour you are seeing: Carlos, if you allow I would like to push this modification for 2.22. > > Bye > Stefan > > On 07/07/2015 11:23 PM, Adhemerval Zanella wrote: >> >> >> On 07-07-2015 16:48, Carlos O'Donell wrote: >>> On 06/16/2015 09:56 AM, Adhemerval Zanella wrote: >>>> Reposting to see if I can land it for 2.22. >>>> >>>> -- >>>> >>>> This patch updates tst-fmemopen2 to check for fmemopen with NULL buffer >>>> inputs and also refactor the code a bit. >>>> >>>> The test relies on a POSIX compliant fmemopen implementation. >>>> >>>> Tested on x86_64, i386, aarch64, and arm-linux-gnueabihf. >>>> >>>> * stdio-common/tst-fmemopen2.c (do_test): Add test for NULL and zero >>>> length buffers. >>>> * stdio-common/tst-fmemopen.c (do_test): Refactor to use >>>> test-skeleton.c. >>> >>> OK with nits fixed and after you checkin the fmemopen fixes. >> >> Thanks for the review, I have updated the patch with all your requests and >> I have also added some more comments about the tests intentions. >> > diff --git a/libio/fmemopen.c b/libio/fmemopen.c index e6e6a49..3ab3e8d 100644 --- a/libio/fmemopen.c +++ b/libio/fmemopen.c @@ -150,7 +150,7 @@ __fmemopen (void *buf, size_t len, const char *mode) cookie_io_functions_t iof; fmemopen_cookie_t *c; - c = (fmemopen_cookie_t *) malloc (sizeof (fmemopen_cookie_t)); + c = (fmemopen_cookie_t *) calloc (sizeof (fmemopen_cookie_t), 1); if (c == NULL) return NULL; @@ -165,7 +165,6 @@ __fmemopen (void *buf, size_t len, const char *mode) return NULL; } c->buffer[0] = '\0'; - c->maxpos = 0; } else { @@ -182,7 +181,8 @@ __fmemopen (void *buf, size_t len, const char *mode) if (mode[0] == 'w' && mode[1] == '+') c->buffer[0] = '\0'; - c->maxpos = strnlen (c->buffer, len); + if (mode[0] == 'a') + c->maxpos = strnlen (c->buffer, len); }