oleaut.c small change to former patch an some more

Dietrich Teickner dietrich_teickner at arcor.de
Sat Jan 1 09:25:34 CST 2005


Hi Alexandre,

I have some problems with SysReAllocStringLen in Odin(wine for os/2) and 
the win32 MySqlQueryBrowser.exe. And I thing wine will have some times 
the same. I thing we can / need no memcpy, if str and old the same 
before realloc. We can reset the source (str) to NULL in this case. This 
should solve the problem for wine and odin.

Happy new Year and regards,

Dietrich

/******************************************************************************
  *             SysReAllocStringLen   [OLEAUT32.5]
  *
  * Change the length of a previously created BSTR.
  *
  * PARAMS
  *  old [O] BSTR to change the length of
  *  str [I] New source for pbstr
  *  len [I] Length of oleStr in wide characters
  *
  * RETURNS
  *  Success: 1. The size of pbstr is updated.
  *  Failure: 0, if len >= 0x80000000 or memory allocation fails.
  *
  * NOTES
  *  See BSTR(), SysAllocStringByteLen().
  *  *pbstr may be changed by this function.
  */
int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* str, unsigned
int len)
{
     if (*old!=NULL) {
       DWORD newbytelen = len*sizeof(WCHAR);
       DWORD *ptr =
HeapReAlloc(GetProcessHeap(),0,((DWORD*)*old)-1,newbytelen+sizeof(WCHAR)+sizeof(DWORD));
       if (*old == str) str = NULL;
// if *old == str, we need no memcpy and HeapReAlloc can also invalid
the source ???
       *old = (BSTR)(ptr+1);
       (*old)[len] = 0;
       *ptr = newbytelen;
       if (str) {
         memcpy(*old, str, newbytelen);
       } else {
	/* Subtle hidden feature: The old string data is still there
	 * when 'in' is NULL!
	 * Some Microsoft program needs it.
	 */
       }
     } else {
       /*
        * Allocate the new string
        */
       *old = SysAllocStringLen(str, len);
     }

     return 1;
}

Why should SysReallocString not work as wrapper to SysReAllocStringLen
/******************************************************************************
  *		SysReAllocString	[OLEAUT32.3]
  *
  * Change the length of a previously created BSTR.
  *
  * PARAMS
  *  old [I/O] BSTR to change the length of
  *  str [I]   New source for pbstr
  *
  * RETURNS
  *  Success: 1
  *  Failure: 0.
  *
  * NOTES
  *  See BSTR(), SysAllocStringStringLen().
  */
INT WINAPI SysReAllocString(LPBSTR old,LPCOLESTR str)
{
     /*
      * Sanity check
      */
     if (old==NULL)  // ?? need we this ??
       return 0;
     /* Delegate this to the SysReAllocStringLen32 method. */
     return SysReAllocStringLen(old, str, lstrlenW(str));
}







More information about the wine-patches mailing list