From patchwork Thu Jul 16 11:46:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 51174 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C4E6B22A28 for ; Thu, 16 Jul 2015 11:47:03 +0000 (UTC) Received: by lagx9 with SMTP id x9sf18042500lag.2 for ; Thu, 16 Jul 2015 04:47:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-subscribe:list-archive:list-post:list-help :sender:delivered-to:message-id:date:from:user-agent:mime-version:to :cc:subject:content-type:content-transfer-encoding:x-original-sender :x-original-authentication-results; bh=Es0GoeK5/F/n+OSENG1FJeokZWmCm5C/hann4yMzUcY=; b=UjZfzmUrnrw7E5iCrG0532KxNzwoK7gu+6UDVDznxrK9ujtqj4u2kzISFwkTUpBYcR gfr1HhzXMX6eAOOoq/GcoEVEVvCy00N+Wp4APuXKXPN4w/5oDv0pqy2e+ZH9JvGkaaVE OvuZBITh7RORcVpjnWxqkP6sg4lOlJt1NNiTLAF7HAnY4hQ+0JuamL2h4xL1tmCViwPX a93nFjBXmUiEwycwOkU3PnBLsPkNusN/+zNHtsV5ArUwt9Yo4y+hblQgrlfjZvR4CGx1 ksp8GdnXJmFbX18z1EVtu4ShQvocdN3W2E2/no1SkKfZ7CEgBY3aHRisMv2zUE5si6Yf 4OZA== X-Gm-Message-State: ALoCoQmn+ja0m+uRSZ4VN82CG9I0EjQUnIdFQeNr78Rb1beIL3qoyeMZvkiLkDzXYCrw8w/LZNN9 X-Received: by 10.112.122.12 with SMTP id lo12mr4666937lbb.5.1437047222628; Thu, 16 Jul 2015 04:47:02 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.146 with SMTP id j18ls337504laa.44.gmail; Thu, 16 Jul 2015 04:47:02 -0700 (PDT) X-Received: by 10.152.3.199 with SMTP id e7mr8824415lae.98.1437047222486; Thu, 16 Jul 2015 04:47:02 -0700 (PDT) Received: from mail-lb0-x232.google.com (mail-lb0-x232.google.com. [2a00:1450:4010:c04::232]) by mx.google.com with ESMTPS id wh7si6720969lbb.123.2015.07.16.04.47.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Jul 2015 04:47:02 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::232 as permitted sender) client-ip=2a00:1450:4010:c04::232; Received: by lblf12 with SMTP id f12so42016675lbl.2 for ; Thu, 16 Jul 2015 04:47:02 -0700 (PDT) X-Received: by 10.112.131.98 with SMTP id ol2mr9215323lbb.56.1437047222388; Thu, 16 Jul 2015 04:47:02 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp201340lbb; Thu, 16 Jul 2015 04:47:01 -0700 (PDT) X-Received: by 10.68.139.136 with SMTP id qy8mr17874363pbb.89.1437047220631; Thu, 16 Jul 2015 04:47:00 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id iw5si12627121pbc.27.2015.07.16.04.46.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Jul 2015 04:47:00 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-61013-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 26972 invoked by alias); 16 Jul 2015 11:46:51 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 26948 invoked by uid 89); 16 Jul 2015 11:46:50 -0000 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-f180.google.com X-Received: by 10.13.240.67 with SMTP id z64mr9263857ywe.69.1437047206794; Thu, 16 Jul 2015 04:46:46 -0700 (PDT) Message-ID: <55A799A3.6040202@linaro.org> Date: Thu, 16 Jul 2015 08:46:43 -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: GNU C Library CC: Carlos O'Donell Subject: [PATCH] libio: Fix fmemopen 'w' mode with provided buffer X-Original-Sender: adhemerval.zanella@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::232 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@sourceware.org X-Google-Group-Id: 836684582541 If 'w' mode is used with a provided buffer the fmemopen will try to find the first null byte to set as maximum internal stream size. It should be done only for append mode ('a'). Kudos for Stefan Liebler for finding this error on s390-32. --- * libio/fmemopen.c (__fmemopen): Fix 'w' openmode with provided buffer. * stdio-common/tst-fmemopen2.c (do_test_with_buffer): Typo. -- 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); } diff --git a/stdio-common/tst-fmemopen2.c b/stdio-common/tst-fmemopen2.c index 16dd3ad..ecd7824 100644 --- a/stdio-common/tst-fmemopen2.c +++ b/stdio-common/tst-fmemopen2.c @@ -34,7 +34,7 @@ do_test_with_buffer (void) FILE *fp = fmemopen (buf, nbuf, "w"); if (fp == NULL) { - printf ("FAIL: fmemopen failedi (%s)\n", __FUNCTION__); + printf ("FAIL: fmemopen failed (%s)\n", __FUNCTION__); return 1; }