From 5101a90bca2bd2618b488f37624af43efe17a0e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Matellanes?= Date: Mon, 11 Jul 2016 11:34:56 +0100 Subject: [PATCH] msvcirt: Reset the pointers on file sync in most cases. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Iván Matellanes Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/msvcirt/msvcirt.c | 4 ++-- dlls/msvcirt/tests/msvcirt.c | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c index 3adaf7425c9..07aea3ee256 100644 --- a/dlls/msvcirt/msvcirt.c +++ b/dlls/msvcirt/msvcirt.c @@ -1126,8 +1126,8 @@ int __thiscall filebuf_sync(filebuf *this) count = this->base.pptr - this->base.pbase; if (count > 0 && _write(this->fd, this->base.pbase, count) != count) return EOF; - this->base.pbase = this->base.pptr = this->base.epptr = NULL; } + this->base.pbase = this->base.pptr = this->base.epptr = NULL; /* flush input buffer */ if (this->base.egptr != NULL) { offset = this->base.egptr - this->base.gptr; @@ -1143,8 +1143,8 @@ int __thiscall filebuf_sync(filebuf *this) if (_lseek(this->fd, -offset, SEEK_CUR) < 0) return EOF; } - this->base.eback = this->base.gptr = this->base.egptr = NULL; } + this->base.eback = this->base.gptr = this->base.egptr = NULL; return 0; } diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c index 3e8b548b5b7..13b83972131 100644 --- a/dlls/msvcirt/tests/msvcirt.c +++ b/dlls/msvcirt/tests/msvcirt.c @@ -1419,6 +1419,46 @@ static void test_filebuf(void) ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr); ok(fb1.base.pptr == NULL, "wrong put pointer, expected %p got %p\n", NULL, fb1.base.pptr); ok(_tell(fb1.fd) == 0, "_tell failed\n"); + fb1.base.pbase = fb1.base.pptr = fb1.base.base; + ret = (int) call_func1(p_filebuf_sync, &fb1); + ok(ret == 0, "wrong return, expected 0 got %d\n", ret); + ok(fb1.base.pbase == NULL, "wrong put base, expected %p got %p\n", NULL, fb1.base.pbase); + ok(fb1.base.pptr == NULL, "wrong put pointer, expected %p got %p\n", NULL, fb1.base.pptr); + fb1.base.epptr = fb1.base.ebuf; + ret = (int) call_func1(p_filebuf_sync, &fb1); + ok(ret == 0, "wrong return, expected 0 got %d\n", ret); + ok(fb1.base.epptr == NULL, "wrong put end, expected %p got %p\n", NULL, fb1.base.epptr); + fb1.base.pbase = fb1.base.base; + ret = (int) call_func1(p_filebuf_sync, &fb1); + ok(ret == 0, "wrong return, expected 0 got %d\n", ret); + ok(fb1.base.pbase == NULL, "wrong put base, expected %p got %p\n", NULL, fb1.base.pbase); + fb1.base.pbase = fb1.base.base; + fb1.base.epptr = fb1.base.ebuf; + ret = (int) call_func1(p_filebuf_sync, &fb1); + ok(ret == 0, "wrong return, expected 0 got %d\n", ret); + ok(fb1.base.pbase == NULL, "wrong put base, expected %p got %p\n", NULL, fb1.base.pbase); + ok(fb1.base.epptr == NULL, "wrong put end, expected %p got %p\n", NULL, fb1.base.epptr); + fb1.base.eback = fb1.base.base; + ret = (int) call_func1(p_filebuf_sync, &fb1); + ok(ret == 0, "wrong return, expected 0 got %d\n", ret); + ok(fb1.base.eback == NULL, "wrong get base, expected %p got %p\n", NULL, fb1.base.eback); + fb1.base.eback = fb1.base.gptr = fb1.base.base; + ret = (int) call_func1(p_filebuf_sync, &fb1); + ok(ret == 0, "wrong return, expected 0 got %d\n", ret); + ok(fb1.base.gptr == NULL, "wrong get base, expected %p got %p\n", NULL, fb1.base.gptr); + fb1.base.gptr = fb1.base.base; + fb1.base.egptr = fb1.base.base + 100; + fb1.base.pbase = fb1.base.base; + ret = (int) call_func1(p_filebuf_sync, &fb1); + ok(ret == -1, "wrong return, expected -1 got %d\n", ret); + ok(fb1.base.gptr == fb1.base.base, "wrong get base, expected %p got %p\n", fb1.base.base, fb1.base.gptr); + ok(fb1.base.egptr == fb1.base.base + 100, "wrong get base, expected %p got %p\n", fb1.base.base + 100, fb1.base.egptr); + ok(fb1.base.pbase == NULL, "wrong put base, expected %p got %p\n", NULL, fb1.base.pbase); + fb1.base.egptr = NULL; + ret = (int) call_func1(p_filebuf_sync, &fb1); + ok(ret == 0, "wrong return, expected 0 got %d\n", ret); + ok(fb1.base.gptr == NULL, "wrong get base, expected %p got %p\n", NULL, fb1.base.gptr); + ok(fb1.base.egptr == NULL, "wrong get base, expected %p got %p\n", NULL, fb1.base.egptr); ret = (int) call_func1(p_filebuf_sync, &fb2); ok(ret == -1, "wrong return, expected -1 got %d\n", ret); fb3.base.eback = fb3.base.base;