[1/6] msvcirt: Don't return negative values in in_avail and out_waiting.
Iván Matellanes
matellanesivan at gmail.com
Wed Oct 19 07:00:51 CDT 2016
Signed-off-by: Iván Matellanes <matellanesivan at gmail.com>
---
dlls/msvcirt/msvcirt.c | 4 ++--
dlls/msvcirt/tests/msvcirt.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 8dfe988..e9103a9 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -556,7 +556,7 @@ DEFINE_THISCALL_WRAPPER(streambuf_in_avail, 4)
int __thiscall streambuf_in_avail(const streambuf *this)
{
TRACE("(%p)\n", this);
- return this->egptr - this->gptr;
+ return (this->egptr - this->gptr > 0) ? this->egptr - this->gptr : 0;
}
/* ?out_waiting at streambuf@@QBEHXZ */
@@ -565,7 +565,7 @@ DEFINE_THISCALL_WRAPPER(streambuf_out_waiting, 4)
int __thiscall streambuf_out_waiting(const streambuf *this)
{
TRACE("(%p)\n", this);
- return this->pptr - this->pbase;
+ return (this->pptr - this->pbase > 0) ? this->pptr - this->pbase : 0;
}
/* Unexported */
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index 113bf0e..7f25cd7 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -200,7 +200,9 @@ static int (*__thiscall p_streambuf_allocate)(streambuf*);
static void (*__thiscall p_streambuf_clrclock)(streambuf*);
static int (*__thiscall p_streambuf_doallocate)(streambuf*);
static void (*__thiscall p_streambuf_gbump)(streambuf*, int);
+static int (*__thiscall p_streambuf_in_avail)(const streambuf*);
static void (*__thiscall p_streambuf_lock)(streambuf*);
+static int (*__thiscall p_streambuf_out_waiting)(const streambuf*);
static int (*__thiscall p_streambuf_pbackfail)(streambuf*, int);
static void (*__thiscall p_streambuf_pbump)(streambuf*, int);
static int (*__thiscall p_streambuf_sbumpc)(streambuf*);
@@ -480,7 +482,9 @@ static BOOL init(void)
SET(p_streambuf_clrclock, "?clrlock at streambuf@@QEAAXXZ");
SET(p_streambuf_doallocate, "?doallocate at streambuf@@MEAAHXZ");
SET(p_streambuf_gbump, "?gbump at streambuf@@IEAAXH at Z");
+ SET(p_streambuf_in_avail, "?in_avail at streambuf@@QEBAHXZ");
SET(p_streambuf_lock, "?lock at streambuf@@QEAAXXZ");
+ SET(p_streambuf_out_waiting, "?out_waiting at streambuf@@QEBAHXZ");
SET(p_streambuf_pbackfail, "?pbackfail at streambuf@@UEAAHH at Z");
SET(p_streambuf_pbump, "?pbump at streambuf@@IEAAXH at Z");
SET(p_streambuf_sbumpc, "?sbumpc at streambuf@@QEAAHXZ");
@@ -657,7 +661,9 @@ static BOOL init(void)
SET(p_streambuf_clrclock, "?clrlock at streambuf@@QAEXXZ");
SET(p_streambuf_doallocate, "?doallocate at streambuf@@MAEHXZ");
SET(p_streambuf_gbump, "?gbump at streambuf@@IAEXH at Z");
+ SET(p_streambuf_in_avail, "?in_avail at streambuf@@QBEHXZ");
SET(p_streambuf_lock, "?lock at streambuf@@QAEXXZ");
+ SET(p_streambuf_out_waiting, "?out_waiting at streambuf@@QBEHXZ");
SET(p_streambuf_pbackfail, "?pbackfail at streambuf@@UAEHH at Z");
SET(p_streambuf_pbump, "?pbump at streambuf@@IAEXH at Z");
SET(p_streambuf_sbumpc, "?sbumpc at streambuf@@QAEHXZ");
@@ -1388,6 +1394,36 @@ static void test_streambuf(void)
ok(sb2.gptr == sb2.egptr, "wrong get pointer, expected %p got %p\n", sb2.egptr, sb2.gptr);
ok(*sb2.gptr == 'X', "expected 'X' in the get area, got %c\n", *sb2.gptr);
+ /* out_waiting */
+ ret = (int) call_func1(p_streambuf_out_waiting, &sb);
+ ok(ret == 9, "expected 9 got %d\n", ret);
+ sb.pptr = sb.pbase;
+ ret = (int) call_func1(p_streambuf_out_waiting, &sb);
+ ok(ret == 0, "expected 0 got %d\n", ret);
+ sb.pptr = sb.pbase - 1;
+ ret = (int) call_func1(p_streambuf_out_waiting, &sb);
+ ok(ret == 0, "expected 0 got %d\n", ret);
+ sb.pptr = NULL;
+ ret = (int) call_func1(p_streambuf_out_waiting, &sb);
+ ok(ret == 0, "expected 0 got %d\n", ret);
+ sb.pptr = sb.epptr;
+ sb.pbase = NULL;
+ ret = (int) call_func1(p_streambuf_out_waiting, &sb);
+ ok(ret == (int)(sb.pptr - sb.pbase), "expected %d got %d\n", (int)(sb.pptr - sb.pbase), ret);
+
+ /* in_avail */
+ ret = (int) call_func1(p_streambuf_in_avail, &sb);
+ ok(ret == 256, "expected 256 got %d\n", ret);
+ sb.gptr = sb.egptr;
+ ret = (int) call_func1(p_streambuf_in_avail, &sb);
+ ok(ret == 0, "expected 0 got %d\n", ret);
+ sb.gptr = sb.egptr + 1;
+ ret = (int) call_func1(p_streambuf_in_avail, &sb);
+ ok(ret == 0, "expected 0 got %d\n", ret);
+ sb.egptr = NULL;
+ ret = (int) call_func1(p_streambuf_in_avail, &sb);
+ ok(ret == 0, "expected 0 got %d\n", ret);
+
SetEvent(lock_arg.test[3]);
WaitForSingleObject(thread, INFINITE);
--
2.7.4
More information about the wine-patches
mailing list