This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] libio: Fix fmemopen 'w' mode with provided buffer
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: libc-alpha at sourceware dot org
- Date: Thu, 16 Jul 2015 10:03:26 -0300
- Subject: Re: [PATCH] libio: Fix fmemopen 'w' mode with provided buffer
- Authentication-results: sourceware.org; auth=none
- References: <55A799A3 dot 6040202 at linaro dot org> <mo8691$1se$1 at ger dot gmane dot org>
On 16-07-2015 08:58, Stefan Liebler wrote:
> As already mentioned in https://www.sourceware.org/ml/libc-alpha/2015-07/msg00455.html, the testcase is now passing on s390-32.
>
> Can you change this printf in case of a failure, too:
Ok, change below:
* libio/fmemopen.c (__fmemopen): Fix 'w' openmode with provided
buffer.
* stdio-common/tst-fmemopen2.c (do_test_with_buffer): Fix typo and
fail output information.
--
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..a2c05c1 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;
}
@@ -69,7 +69,7 @@ do_test_with_buffer (void)
if (o != nstr)
{
printf ("FAIL: third ftello returned %jd, expected %zu\n",
- (intmax_t)o, nbuf);
+ (intmax_t)o, nstr);
result = 1;
}