Browse Source

CDataTable::DataEqual: perform GlobalUnlock _after_ memcmp

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@11 595ec19a-5cb4-439b-94a8-42fb3063c22c
ingenuus 22 years ago
parent
commit
c539b2d8d4
1 changed files with 26 additions and 2 deletions
  1. 26 2
      DataTable.cpp

+ 26 - 2
DataTable.cpp

@@ -187,20 +187,44 @@ void CDataTable::Open(int nOpenType, LPCTSTR lpszSql, int nOptions)
 
 BOOL CDataTable::DataEqual(HGLOBAL hgData)
 {
+int nRet;
+int sizeGiven = GlobalSize(hgData);
+int sizeSelf = GlobalSize(m_ooData.m_hData);
+
+	//GlobalSize is allocated space and not necessarily the size of the data
+	//Should we assume that the Data being compared are the same size?
+	// so far in my tests:
+	//  GlobalSize( hgData ) == accurate size of the data contained
+	//  GlobalSize( m_ooData.m_hData ) == 0x00008000
+	//	  - this is true even after locking the memory.
+//	if( sizeGiven != m_ooData.m_dwDataLength )
+//	{
+//		ASSERT(FALSE);
+//		return FALSE;
+//	}
+
 	LPVOID saved = NULL;
 	saved = GlobalLock(m_ooData.m_hData);
 	if(!saved)
+	{
+		ASSERT(FALSE);
 		return FALSE;
+	}
 
 	LPVOID data = NULL;
 	data = GlobalLock(hgData);
 	if(!data)
+	{
+		GlobalUnlock(m_ooData.m_hData);
+		ASSERT(FALSE);
 		return FALSE;
+	}
 
+	nRet = (memcmp(data, saved, m_ooData.m_dwDataLength) == 0);
+
+	// unlock after the compare
 	GlobalUnlock(hgData);
 	GlobalUnlock(m_ooData.m_hData);
 
-	int nRet = (memcmp(data, saved, m_ooData.m_dwDataLength) == 0);
-
 	return nRet;
 }