Piotr Caban : msvcrt: Handle negative file->_cnt value in _flsbuf function.

Alexandre Julliard julliard at winehq.org
Tue Feb 7 15:53:56 CST 2012


Module: wine
Branch: master
Commit: c39793087d11a562655e636489042c2bc2baf63c
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=c39793087d11a562655e636489042c2bc2baf63c

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Tue Feb  7 10:14:03 2012 +0100

msvcrt: Handle negative file->_cnt value in _flsbuf function.

---

 dlls/msvcrt/file.c       |    2 +-
 dlls/msvcrt/tests/file.c |   15 +++++++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index b27a40f..c15e33f 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -3088,7 +3088,7 @@ int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file)
     if(file->_bufsiz) {
         int res = 0;
 
-        if(file->_cnt == 0)
+        if(file->_cnt <= 0)
             res = msvcrt_flush_buffer(file);
         if(!res) {
             *file->_ptr++ = c;
diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c
index e7b7353..b9b904d 100644
--- a/dlls/msvcrt/tests/file.c
+++ b/dlls/msvcrt/tests/file.c
@@ -544,10 +544,21 @@ static void test_flsbuf( void )
                          bufmodes[bufmode], 0, ret);
     ret = _flsbuf(0xff,tempfh);
     ok(0xff == ret, "_flsbuf(0xff,tempfh) with bufmode %x expected %x got %x\n",
-                         bufmodes[bufmode], 0, ret);
+                         bufmodes[bufmode], 0xff, ret);
     ret = _flsbuf(0xffffffff,tempfh);
     ok(0xff == ret, "_flsbuf(0xffffffff,tempfh) with bufmode %x expected %x got %x\n",
-                         bufmodes[bufmode], 0, ret);
+                         bufmodes[bufmode], 0xff, ret);
+    if(tempfh->_base) {
+        fputc('x', tempfh);
+        tempfh->_cnt = -1;
+        tempfh->_base[1] = 'a';
+        ret = _flsbuf(0xab,tempfh);
+        ok(ret == 0xab, "_flsbuf(0xab,tempfh) with bufmode %x expected 0xab got %x\n",
+                bufmodes[bufmode], ret);
+        ok(tempfh->_base[1] == 'a', "tempfh->_base[1] should not be changed (%d)\n",
+                tempfh->_base[1]);
+    }
+
     fclose(tempfh);
   }
 




More information about the wine-cvs mailing list