Commit 025c5434 authored by Iván Matellanes's avatar Iván Matellanes Committed by Alexandre Julliard

msvcirt: Fix implementation of strstreambuf::underflow.

Spotted while testing for ostream printing. Signed-off-by: 's avatarIván Matellanes <matellanes.ivan@gmail.com> Signed-off-by: 's avatarPiotr Caban <piotr@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent eeec1b1a
......@@ -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;
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment