[1/2] msvcirt: Some streambuf members should return an unsigned character

Iván Matellanes matellanesivan at gmail.com
Wed Jul 6 10:31:59 CDT 2016


Signed-off-by: Iván Matellanes <matellanes.ivan at gmail.com>
---
 dlls/msvcirt/msvcirt.c       |  6 +++---
 dlls/msvcirt/tests/msvcirt.c | 22 +++++++++++++++++++++-
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 5f44854..d2cd77a 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -740,7 +740,7 @@ DEFINE_THISCALL_WRAPPER(streambuf_sputc, 8)
 int __thiscall streambuf_sputc(streambuf *this, int ch)
 {
     TRACE("(%p %d)\n", this, ch);
-    return (this->pptr < this->epptr) ? *this->pptr++ = ch : call_streambuf_overflow(this, ch);
+    return (this->pptr < this->epptr) ? (unsigned char)(*this->pptr++ = ch) : call_streambuf_overflow(this, ch);
 }
 
 /* ?sgetn at streambuf@@QAEHPADH at Z */
@@ -773,7 +773,7 @@ int __thiscall streambuf_snextc(streambuf *this)
         if (this->gptr >= this->egptr)
             call_streambuf_underflow(this);
         this->gptr++;
-        return (this->gptr < this->egptr) ? *this->gptr : call_streambuf_underflow(this);
+        return (this->gptr < this->egptr) ? (unsigned char)(*this->gptr) : call_streambuf_underflow(this);
     }
 }
 
@@ -792,7 +792,7 @@ int __thiscall streambuf_sbumpc(streambuf *this)
         if (ret == EOF)
             ret = call_streambuf_underflow(this);
     } else {
-        ret = (this->gptr < this->egptr) ? *this->gptr : call_streambuf_underflow(this);
+        ret = (this->gptr < this->egptr) ? (unsigned char)(*this->gptr) : call_streambuf_underflow(this);
         this->gptr++;
     }
     return ret;
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index ad2b8f7..fb228fa 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -901,6 +901,18 @@ static void test_streambuf(void)
     ok(overflow_count == 0, "no call to overflow expected\n");
     ok(*sb.pbase == 'c', "expected 'c' in the put area, got %c\n", *sb.pbase);
     ok(sb.pptr == sb.pbase + 1, "wrong put pointer, expected %p got %p\n", sb.pbase + 1, sb.pptr);
+    sb.pptr--;
+    ret = (int) call_func2(p_streambuf_sputc, &sb, 150);
+    ok(ret == 150, "wrong return value, expected 150 got %d\n", ret);
+    ok(overflow_count == 0, "no call to overflow expected\n");
+    ok(*sb.pbase == -106, "expected -106 in the put area, got %d\n", *sb.pbase);
+    ok(sb.pptr == sb.pbase + 1, "wrong put pointer, expected %p got %p\n", sb.pbase + 1, sb.pptr);
+    sb.pptr--;
+    ret = (int) call_func2(p_streambuf_sputc, &sb, -50);
+    ok(ret == 206, "wrong return value, expected 206 got %d\n", ret);
+    ok(overflow_count == 0, "no call to overflow expected\n");
+    ok(*sb.pbase == -50, "expected -50 in the put area, got %d\n", *sb.pbase);
+    ok(sb.pptr == sb.pbase + 1, "wrong put pointer, expected %p got %p\n", sb.pbase + 1, sb.pptr);
     test_this = &sb2;
     ret = (int) call_func2(p_streambuf_sputc, &sb2, 'c');
     ok(ret == 'c', "wrong return value, expected 'c' got %d\n", ret);
@@ -996,6 +1008,10 @@ static void test_streambuf(void)
     ret = (int) call_func1(p_streambuf_snextc, &sb);
     ok(ret == 'e', "expected 'e' got '%c'\n", ret);
     ok(sb.gptr == sb.eback + 1, "wrong get pointer, expected %p got %p\n", sb.eback + 1, sb.gptr);
+    *sb.gptr-- = -50;
+    ret = (int) call_func1(p_streambuf_snextc, &sb);
+    ok(ret == 206, "expected 206 got %d\n", ret);
+    ok(sb.gptr == sb.eback + 1, "wrong get pointer, expected %p got %p\n", sb.eback + 1, sb.gptr);
     test_this = &sb2;
     ret = (int) call_func1(p_streambuf_snextc, &sb2);
     ok(ret == EOF, "expected EOF got '%c'\n", ret);
@@ -1043,8 +1059,12 @@ static void test_streambuf(void)
     ok(underflow_count == 49, "expected 2 calls to underflow, got %d\n", underflow_count - 47);
 
     /* sbumpc */
+    sb.gptr = sb.eback;
     ret = (int) call_func1(p_streambuf_sbumpc, &sb);
-    ok(ret == 'e', "expected 'e' got '%c'\n", ret);
+    ok(ret == 'T', "expected 'T' got '%c'\n", ret);
+    ok(sb.gptr == sb.eback + 1, "wrong get pointer, expected %p got %p\n", sb.eback + 1, sb.gptr);
+    ret = (int) call_func1(p_streambuf_sbumpc, &sb);
+    ok(ret == 206, "expected 206 got %d\n", ret);
     ok(sb.gptr == sb.eback + 2, "wrong get pointer, expected %p got %p\n", sb.eback + 2, sb.gptr);
     test_this = &sb2;
     ret = (int) call_func1(p_streambuf_sbumpc, &sb2);
-- 
2.7.4




More information about the wine-patches mailing list