msvcirt: Fix implementation of strstreambuf::underflow.

Spotted while testing for ostream printing.

Signed-off-by: Iván Matellanes <matellanes.ivan@gmail.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Iván Matellanes 2016-06-20 13:32:09 +01:00 committed by Alexandre Julliard
parent eeec1b1a64
commit 025c543442
2 changed files with 32 additions and 1 deletions

View File

@ -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;
}

View File

@ -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);