This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 3/6][BZ #14292] Do not inverse seek in fmemopen_seek.


Same as  http://sourceware.org/ml/libc-alpha/2013-05/msg00737.html

Compatibility is handled by previous commit.

Only change here is added testcase.

	* libio/Makefile (tests): Add bug-fmemopen1.
	* libio/bug-fmemopen1: New file.
	* libio/fmemopen.c (fopen_seek): Do not inverse seek.
---
 libio/Makefile        |    1 +
 libio/bug-fmemopen1.c |   23 +++++++++++++++++++++++
 libio/fmemopen.c      |    2 +-
 3 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 libio/bug-fmemopen1.c

diff --git a/libio/Makefile b/libio/Makefile
index 1e3e67f..e4bbe0f 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -59,6 +59,7 @@ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc   \
 	tst-memstream1 tst-memstream2 \
 	tst-wmemstream1 tst-wmemstream2 \
 	bug-memstream1 bug-wmemstream1 \
+	bug-fmemopen1 \
 	tst-setvbuf1 tst-popen1 tst-fgetwc bug-wsetpos tst-fseek \
 	tst-fwrite-error
 ifeq (yes,$(build-shared))
diff --git a/libio/bug-fmemopen1.c b/libio/bug-fmemopen1.c
new file mode 100644
index 0000000..d20dbe1
--- /dev/null
+++ b/libio/bug-fmemopen1.c
@@ -0,0 +1,25 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+int
+do_test (int argc, char **argv)
+{
+  FILE *stream;
+  char buffer[] = "foobar";
+  char s[] = "a";
+
+  stream = fmemopen (buffer, sizeof (buffer), "wb");
+  fseek (stream, -1, SEEK_END);
+  fprintf (stream, s);
+  fclose (stream);
+
+  if (buffer[sizeof (buffer) - 1] != s[0])
+    {
+      printf ("Disagree at position %i.\n", sizeof (buffer) - 1);
+      return 1;
+    }
+
+  return 0;
+}
+
+#include <../test-skeleton.c>
diff --git a/libio/fmemopen.c b/libio/fmemopen.c
index c897a3c..7ddbb89 100644
--- a/libio/fmemopen.c
+++ b/libio/fmemopen.c
@@ -165,7 +165,7 @@ fmemopen_seek (void *cookie, _IO_off64_t *p, int w)
       break;
 
     case SEEK_END:
-      np = (c->binmode ? c->size : c->maxpos) - *p;
+      np = (c->binmode ? c->size : c->maxpos) + *p;
       break;
 
     default:
-- 
1.7.10.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]