From 025c54344230ca8b32e80f08b9af13a16dfd2445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Matellanes?= Date: Mon, 20 Jun 2016 13:32:09 +0100 Subject: [PATCH] msvcirt: Fix implementation of strstreambuf::underflow. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Spotted while testing for ostream printing. Signed-off-by: Iván Matellanes Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/msvcirt/msvcirt.c | 5 ++++- dlls/msvcirt/tests/msvcirt.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c index fe5901a12c0..e4fb3fb0aed 100644 --- a/dlls/msvcirt/msvcirt.c +++ b/dlls/msvcirt/msvcirt.c @@ -1469,8 +1469,11 @@ int __thiscall strstreambuf_underflow(strstreambuf *this) if (this->base.gptr < this->base.egptr) return *this->base.gptr; /* extend the get area to include the characters written */ - if (this->base.egptr < this->base.pptr) + if (this->base.egptr < this->base.pptr) { + this->base.gptr = this->base.base + (this->base.gptr - this->base.eback); + this->base.eback = this->base.base; this->base.egptr = this->base.pptr; + } return (this->base.gptr < this->base.egptr) ? *this->base.gptr : EOF; } diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c index a6916c1ec06..428ddf32a51 100644 --- a/dlls/msvcirt/tests/msvcirt.c +++ b/dlls/msvcirt/tests/msvcirt.c @@ -1745,8 +1745,36 @@ static void test_strstreambuf(void) ssb2.base.pbase = ssb2.base.pptr = ssb2.base.epptr = NULL; ret = (int) call_func1(p_strstreambuf_underflow, &ssb2); ok(ret == EOF, "expected EOF got %d\n", ret); + ssb2.base.pbase = ssb2.base.pptr = ssb2.base.base; + ret = (int) call_func1(p_strstreambuf_underflow, &ssb2); + ok(ret == EOF, "expected EOF got %d\n", ret); + ok(ssb2.base.eback == ssb2.base.base, "wrong get base, expected %p got %p\n", ssb2.base.base, ssb2.base.eback); + ok(ssb2.base.gptr == ssb2.base.base, "wrong get pointer, expected %p got %p\n", ssb2.base.base, ssb2.base.gptr); + ok(ssb2.base.egptr == ssb2.base.base, "wrong get end, expected %p got %p\n", ssb2.base.base, ssb2.base.egptr); + ssb2.base.pptr = ssb2.base.base + 3; + ret = (int) call_func1(p_strstreambuf_underflow, &ssb2); + ok(ret == 'C', "expected 'C' got %d\n", ret); + ok(ssb2.base.eback == ssb2.base.base, "wrong get base, expected %p got %p\n", ssb2.base.base, ssb2.base.eback); + ok(ssb2.base.gptr == ssb2.base.base, "wrong get pointer, expected %p got %p\n", ssb2.base.base, ssb2.base.gptr); + ok(ssb2.base.egptr == ssb2.base.base + 3, "wrong get end, expected %p got %p\n", ssb2.base.base + 3, ssb2.base.egptr); + ssb2.base.gptr = ssb2.base.base + 2; + ssb2.base.egptr = NULL; + ret = (int) call_func1(p_strstreambuf_underflow, &ssb2); + ok(ret == 'e', "expected 'e' got %d\n", ret); + ok(ssb2.base.eback == ssb2.base.base, "wrong get base, expected %p got %p\n", ssb2.base.base, ssb2.base.eback); + ok(ssb2.base.gptr == ssb2.base.base + 2, "wrong get pointer, expected %p got %p\n", ssb2.base.base, ssb2.base.gptr); + ok(ssb2.base.egptr == ssb2.base.base + 3, "wrong get end, expected %p got %p\n", ssb2.base.base + 3, ssb2.base.egptr); + ssb2.base.eback = ssb2.base.egptr = ssb2.base.base + 1; + ssb2.base.gptr = ssb2.base.base + 3; + ssb2.base.pptr = ssb2.base.base + 5; + ret = (int) call_func1(p_strstreambuf_underflow, &ssb2); + ok(ret == 'e', "expected 'e' got %d\n", ret); + ok(ssb2.base.eback == ssb2.base.base, "wrong get base, expected %p got %p\n", ssb2.base.base, ssb2.base.eback); + ok(ssb2.base.gptr == ssb2.base.base + 2, "wrong get pointer, expected %p got %p\n", ssb2.base.base, ssb2.base.gptr); + ok(ssb2.base.egptr == ssb2.base.base + 5, "wrong get end, expected %p got %p\n", ssb2.base.base + 5, ssb2.base.egptr); ssb2.base.eback = ssb2.base.base; ssb2.base.gptr = ssb2.base.egptr = ssb2.base.ebuf; + ssb2.base.pbase = ssb2.base.pptr = NULL; ret = (int) call_func1(p_strstreambuf_underflow, &ssb2); ok(ret == EOF, "expected EOF got %d\n", ret);