RICHED20: mimic Windows behaviour for buggy EM_STREAMOUT callbacks

Krzysztof Foltman wdev at foltman.com
Sun Jun 19 03:41:28 CDT 2005


ChangeLog:
  * Fix a warning caused by the TAB patch
  * Initialize *pcb to a large value before calling the stream-out 
callback (to make applications that don't set *pcb at all happy)
  * Don't flush the output stream when error condition is set

Krzysztof

-------------- next part --------------
Index: writer.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/writer.c,v
retrieving revision 1.6
diff -u -r1.6 writer.c
--- writer.c	12 Jun 2005 11:08:29 -0000	1.6
+++ writer.c	19 Jun 2005 08:36:15 -0000
@@ -45,11 +45,23 @@
 {
   LONG nStart = 0;
   LONG nWritten = 0;
+  LONG nRemaining = 0;
   EDITSTREAM *stream = editor->pStream->stream;
 
   do {
+    TRACE("sending %lu bytes\n", editor->pStream->pos - nStart);
+    /* Some apps seem not to set *pcb unless a problem arises, relying
+      on initial random nWritten value, which is usually >STREAMOUT_BUFFER_SIZE */
+    nRemaining = editor->pStream->pos - nStart;
+    nWritten = 0xDEADBEEF;
     stream->dwError = stream->pfnCallback(stream->dwCookie, editor->pStream->buffer + nStart,
                                           editor->pStream->pos - nStart, &nWritten);
+    TRACE("error=%lu written=%lu\n", stream->dwError, nWritten);
+    if (nWritten > (editor->pStream->pos - nStart) || nWritten<0) {
+      FIXME("Invalid returned written size *pcb: 0x%x (%ld) instead of %ld\n", 
+            (unsigned)nWritten, nWritten, nRemaining);
+      nWritten = nRemaining;
+    }
     if (nWritten == 0 || stream->dwError)
       return FALSE;
     editor->pStream->written += nWritten;
@@ -64,6 +76,7 @@
 ME_StreamOutFree(ME_TextEditor *editor)
 {
   LONG written = editor->pStream->written;
+  TRACE("total length = %lu\n", written);
 
   FREE_OBJ(editor->pStream);
   editor->pStream = NULL;
@@ -782,7 +795,7 @@
     ME_StreamOutRTF(editor, nStart, nTo - nStart, dwFormat);
   else if (dwFormat & SF_TEXT || dwFormat & SF_TEXTIZED)
     ME_StreamOutText(editor, nStart, nTo - nStart, dwFormat);
-  
-  ME_StreamOutFlush(editor);
+  if (!editor->pStream->stream->dwError)
+    ME_StreamOutFlush(editor);
   return ME_StreamOutFree(editor);
 }


More information about the wine-patches mailing list