Robert Shearman : rpcrt4: Improve ReadVariance.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Jan 9 13:52:47 CST 2006


Module: wine
Branch: refs/heads/master
Commit: 1926b6da63e939fb0e21fa2183e1dc5f4e755245
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=1926b6da63e939fb0e21fa2183e1dc5f4e755245

Author: Robert Shearman <rob at codeweavers.com>
Date:   Mon Jan  9 17:21:01 2006 +0100

rpcrt4: Improve ReadVariance.
Extend ReadVariance to read the offset as well as the actual count,
since these always come in pairs.
Handle the variance not being present in ReadVariance and always call
it from the unmarshalling functions to simplify the code there and
also to fix a bug where the format pointer wasn't advanced properly
for complex arrays (introduced in the previous patch when implementing
variance).

---

 dlls/rpcrt4/ndr_marshall.c |   35 ++++++++++++++++-------------------
 1 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/dlls/rpcrt4/ndr_marshall.c b/dlls/rpcrt4/ndr_marshall.c
index def590d..026f517 100644
--- a/dlls/rpcrt4/ndr_marshall.c
+++ b/dlls/rpcrt4/ndr_marshall.c
@@ -315,9 +315,21 @@ PFORMAT_STRING ReadConformance(MIDL_STUB
 
 static inline PFORMAT_STRING ReadVariance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
 {
+  if (!IsConformanceOrVariancePresent(pFormat))
+  {
+    pStubMsg->Offset = 0;
+    pStubMsg->ActualCount = pStubMsg->MaxCount;
+    goto done;
+  }
+
+  pStubMsg->Offset      = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
+  pStubMsg->Buffer += 4;
+  TRACE("offset is %ld\n", pStubMsg->Offset);
   pStubMsg->ActualCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
   pStubMsg->Buffer += 4;
-  TRACE("unmarshalled variance is %ld\n", pStubMsg->ActualCount);
+  TRACE("variance is %ld\n", pStubMsg->ActualCount);
+
+done:
   return pFormat+4;
 }
 
@@ -2008,7 +2020,6 @@ unsigned char* WINAPI NdrConformantVaryi
                                                            PFORMAT_STRING pFormat,
                                                            unsigned char fMustAlloc )
 {
-    DWORD offset;
     DWORD esize = *(const WORD*)(pFormat+2);
 
     TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
@@ -2020,13 +2031,11 @@ unsigned char* WINAPI NdrConformantVaryi
         return NULL;
     }
     pFormat = ReadConformance(pStubMsg, pFormat);
-    offset = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
-    pStubMsg->Buffer += 4;
     pFormat = ReadVariance(pStubMsg, pFormat);
 
     if (!*ppMemory || fMustAlloc)
         *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
-    memcpy(*ppMemory + offset, pStubMsg->Buffer, pStubMsg->ActualCount * esize);
+    memcpy(*ppMemory + pStubMsg->Offset, pStubMsg->Buffer, pStubMsg->ActualCount * esize);
     pStubMsg->Buffer += pStubMsg->ActualCount * esize;
 
     EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
@@ -2141,7 +2150,7 @@ unsigned char * WINAPI NdrComplexArrayUn
                                                  PFORMAT_STRING pFormat,
                                                  unsigned char fMustAlloc)
 {
-  ULONG offset, count, esize;
+  ULONG count, esize;
   unsigned char *pMemory;
 
   TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
@@ -2156,19 +2165,7 @@ unsigned char * WINAPI NdrComplexArrayUn
   pFormat += 4;
 
   pFormat = ReadConformance(pStubMsg, pFormat);
-  TRACE("conformance = %ld\n", pStubMsg->MaxCount);
-  if (IsConformanceOrVariancePresent(pFormat))
-  {
-    offset = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
-    pStubMsg->Buffer += 4;
-    pFormat = ReadVariance(pStubMsg, pFormat);
-    TRACE("variance = %ld\n", pStubMsg->ActualCount);
-  }
-  else
-  {
-    offset = 0;
-    pStubMsg->ActualCount = pStubMsg->MaxCount;
-  }
+  pFormat = ReadVariance(pStubMsg, pFormat);
 
   esize = ComplexStructSize(pStubMsg, pFormat);
 




More information about the wine-cvs mailing list