Index: ext/libicpf/src/libicpf/cfg_xml.cpp
===================================================================
diff -u -rf59b3a0da37558c2af6b13a6a88ed16196c05832 -r361d7f8b9268e18f39e298ea82425f7ddb24fb43
--- ext/libicpf/src/libicpf/cfg_xml.cpp	(.../cfg_xml.cpp)	(revision f59b3a0da37558c2af6b13a6a88ed16196c05832)
+++ ext/libicpf/src/libicpf/cfg_xml.cpp	(.../cfg_xml.cpp)	(revision 361d7f8b9268e18f39e298ea82425f7ddb24fb43)
@@ -1,5 +1,5 @@
 #include "cfg_xml.h"
-#include <expat.h>
+//#include <expat.h>
 #include "exception.h"
 #include <string>
 #include <map>
Index: ext/libicpf/src/libicpf/circ_buffer.cpp
===================================================================
diff -u -rb337c059691a6940b52a86388ff427c734be8eb6 -r361d7f8b9268e18f39e298ea82425f7ddb24fb43
--- ext/libicpf/src/libicpf/circ_buffer.cpp	(.../circ_buffer.cpp)	(revision b337c059691a6940b52a86388ff427c734be8eb6)
+++ ext/libicpf/src/libicpf/circ_buffer.cpp	(.../circ_buffer.cpp)	(revision 361d7f8b9268e18f39e298ea82425f7ddb24fb43)
@@ -21,6 +21,8 @@
 #include <stddef.h>
 #include <string.h>
 #include <assert.h>
+#include "err_codes.h"
+#include "exception.h"
 
 BEGIN_ICPF_NAMESPACE
 
@@ -267,6 +269,9 @@
 int circular_buffer::forward_seek(ulong_t ulFnd)
 {
 	assert(m_pbyBuffer);
+	if(!m_pbyBuffer)
+		THROW(_t("Invalid member"), GE_INVALIDARG, 0, 0);
+
 	if (m_tDataSize < sizeof(ulong_t))
 		return FS_PARTIAL;		// cannot tell if there is such a value (may be a part of it)
 	
@@ -471,7 +476,9 @@
 	assert(m_pbyBuffer);
 	assert(ulBitsCount >= 1 && ulBitsCount <=8);
 	assert(pfn);
-	
+	if(!pfn || ! m_pbyBuffer || ulBitsCount < 1 || ulBitsCount > 8)
+		THROW(_t("Invalid member or argument"), GE_INVALIDARG, 0, 0);
+
 	ushort_t w=0;		// internal buffer for the next data from the class's buffer
 	ulong_t ulBits=0;	// count of bits that was left in w
 	
Index: ext/libicpf/src/libicpf/config_property.cpp
===================================================================
diff -u -rb337c059691a6940b52a86388ff427c734be8eb6 -r361d7f8b9268e18f39e298ea82425f7ddb24fb43
--- ext/libicpf/src/libicpf/config_property.cpp	(.../config_property.cpp)	(revision b337c059691a6940b52a86388ff427c734be8eb6)
+++ ext/libicpf/src/libicpf/config_property.cpp	(.../config_property.cpp)	(revision 361d7f8b9268e18f39e298ea82425f7ddb24fb43)
@@ -1,4 +1,6 @@
 #include "config_property.h"
+#include "exception.h"
+#include "err_codes.h"
 #include <vector>
 #include <assert.h>
 
@@ -318,6 +320,8 @@
 const tchar_t* property::get_value(tchar_t* pszString, size_t stMaxSize, size_t stIndex)
 {
 	assert(pszString);
+	if(!pszString)
+		THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0);
 
 	if (m_uiPropType & flag_array)
 	{
@@ -880,6 +884,9 @@
 bool property::bool_from_string(const tchar_t* pszSrc)
 {
 	assert(pszSrc);
+	if(!pszSrc)
+		THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0);
+
 	return pszSrc[0] != _t('0');
 }
 
Index: ext/libicpf/src/libicpf/crc32.cpp
===================================================================
diff -u -rb337c059691a6940b52a86388ff427c734be8eb6 -r361d7f8b9268e18f39e298ea82425f7ddb24fb43
--- ext/libicpf/src/libicpf/crc32.cpp	(.../crc32.cpp)	(revision b337c059691a6940b52a86388ff427c734be8eb6)
+++ ext/libicpf/src/libicpf/crc32.cpp	(.../crc32.cpp)	(revision 361d7f8b9268e18f39e298ea82425f7ddb24fb43)
@@ -22,6 +22,8 @@
  */
 
 #include "crc32.h"
+#include "err_codes.h"
+#include "exception.h"
 #include <assert.h>
 #ifndef _WIN32
     #include <unistd.h>
@@ -131,6 +133,9 @@
 void crc32_begin(uint_t *puiValue)
 {
 	assert(puiValue != NULL);
+	if(!puiValue)
+		THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0);
+
 	*puiValue=0xffffffff;
 }
 
@@ -143,6 +148,8 @@
 void crc32_partial(uint_t *puiPrev, const byte_t *pbyData, size_t tLen)
 {
 	assert(puiPrev && pbyData);
+	if(!puiPrev || !pbyData)
+		THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0);
 
 	for (size_t i=0;i<tLen;i++)
 		__crc32partial(pbyData[i], puiPrev);
Index: ext/libicpf/src/libicpf/dumpctx.cpp
===================================================================
diff -u -rb337c059691a6940b52a86388ff427c734be8eb6 -r361d7f8b9268e18f39e298ea82425f7ddb24fb43
--- ext/libicpf/src/libicpf/dumpctx.cpp	(.../dumpctx.cpp)	(revision b337c059691a6940b52a86388ff427c734be8eb6)
+++ ext/libicpf/src/libicpf/dumpctx.cpp	(.../dumpctx.cpp)	(revision 361d7f8b9268e18f39e298ea82425f7ddb24fb43)
@@ -151,7 +151,7 @@
  */
 void dumpctx::dump(const tchar_t* pszName, const tchar_t cValue)
 {
-	_sntprintf(m_szBuffer, max_dump, STRFMT _t(" (tchar_t):\n\t'") CHARFMT _t("' (hex: ") CXFMT _t(" / dec: ") CFMT _t(")\n"), pszName, cValue, (short_t)cValue, (short_t)cValue);
+	_sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (tchar_t):\n\t'") TCHRFMT _t("' (hex: ") CXFMT _t(" / dec: ") CFMT _t(")\n"), pszName, cValue, (short_t)cValue, (short_t)cValue);
 	m_szBuffer[max_dump-1]=_t('\0');
 	MLOCK(m_lock);
 	*m_pBuffer+=m_szBuffer;
@@ -164,7 +164,7 @@
  */
 void dumpctx::dump(const tchar_t* pszName, const short_t sValue)
 {
-	_sntprintf(m_szBuffer, max_dump, STRFMT _t(" (short_t):\n\t") SFMT _t(" (hex: ") SXFMT _t(")\n"), pszName, sValue, sValue);
+	_sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (short_t):\n\t") SFMT _t(" (hex: ") SXFMT _t(")\n"), pszName, sValue, sValue);
 	m_szBuffer[max_dump-1]=_t('\0');
 	MLOCK(m_lock);
 	*m_pBuffer+=m_szBuffer;
@@ -177,7 +177,7 @@
  */
 void dumpctx::dump(const tchar_t* pszName, const int_t iValue)
 {
-	_sntprintf(m_szBuffer, max_dump, STRFMT _t(" (int_t):\n\t") LFMT _t(" (hex: ") LXFMT _t(")\n"), pszName, iValue, iValue);
+	_sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (int_t):\n\t") LFMT _t(" (hex: ") LXFMT _t(")\n"), pszName, iValue, iValue);
 	m_szBuffer[max_dump-1]=_t('\0');
 	MLOCK(m_lock);
 	*m_pBuffer+=m_szBuffer;
@@ -190,7 +190,7 @@
  */
 void dumpctx::dump(const tchar_t* pszName, const uchar_t ucValue)
 {
-	_sntprintf(m_szBuffer, max_dump, STRFMT _t(" (uchar_t):\n\t'") UCHARFMT _t("' (hex: ") UCXFMT _t(" / dec: ") UCFMT _t(")\n"), pszName, ucValue, (ushort_t)ucValue, (ushort_t)ucValue);
+	_sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (uchar_t):\n\t'") UCHARFMT _t("' (hex: ") UCXFMT _t(" / dec: ") UCFMT _t(")\n"), pszName, ucValue, (ushort_t)ucValue, (ushort_t)ucValue);
 	m_szBuffer[max_dump-1]=_t('\0');
 	MLOCK(m_lock);
 	*m_pBuffer+=m_szBuffer;
@@ -203,7 +203,7 @@
  */
 void dumpctx::dump(const tchar_t* pszName, const ushort_t usValue)
 {
-	_sntprintf(m_szBuffer, max_dump, STRFMT _t(" (ushort_t):\n\t") USFMT _t(" (hex: ") USXFMT _t(")\n"), pszName, usValue, usValue);
+	_sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (ushort_t):\n\t") USFMT _t(" (hex: ") USXFMT _t(")\n"), pszName, usValue, usValue);
 	m_szBuffer[max_dump-1]=_t('\0');
 	MLOCK(m_lock);
 	*m_pBuffer+=m_szBuffer;
@@ -216,7 +216,7 @@
  */
 void dumpctx::dump(const tchar_t* pszName, const uint_t uiValue)
 {
-	_sntprintf(m_szBuffer, max_dump, STRFMT _t(" (uint_t):\n\t") ULFMT _t(" (hex: ") ULXFMT _t(")\n"), pszName, uiValue, uiValue);
+	_sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (uint_t):\n\t") ULFMT _t(" (hex: ") ULXFMT _t(")\n"), pszName, uiValue, uiValue);
 	m_szBuffer[max_dump-1]=_t('\0');
 	MLOCK(m_lock);
 	*m_pBuffer+=m_szBuffer;
@@ -229,7 +229,7 @@
  */
 void dumpctx::dump(const tchar_t* pszName, const longlong_t llValue)
 {
-	_sntprintf(m_szBuffer, max_dump, STRFMT _t(" (longlong_t):\n\t") LLFMT _t(" (hex: ") LLXFMT _t(")\n"), pszName, llValue, llValue);
+	_sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (longlong_t):\n\t") LLFMT _t(" (hex: ") LLXFMT _t(")\n"), pszName, llValue, llValue);
 	m_szBuffer[max_dump-1]=_t('\0');
 	MLOCK(m_lock);
 	*m_pBuffer+=m_szBuffer;
@@ -242,7 +242,7 @@
  */
 void dumpctx::dump(const tchar_t* pszName, const ulonglong_t ullValue)
 {
-	_sntprintf(m_szBuffer, max_dump, STRFMT _t(" (ulonglong_t):\n\t") ULLFMT _t(" (hex: ") ULLXFMT _t(")\n"), pszName, ullValue, ullValue);
+	_sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (ulonglong_t):\n\t") ULLFMT _t(" (hex: ") ULLXFMT _t(")\n"), pszName, ullValue, ullValue);
 	m_szBuffer[max_dump-1]=_t('\0');
 	MLOCK(m_lock);
 	*m_pBuffer+=m_szBuffer;
@@ -255,7 +255,7 @@
  */
 void dumpctx::dump(const tchar_t* pszName, const ptr_t pValue)
 {
-	_sntprintf(m_szBuffer, max_dump, STRFMT _t(" (ptr_t):\n\t") PTRFMT _t("\n"), pszName, pValue);
+	_sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (ptr_t):\n\t") PTRFMT _t("\n"), pszName, pValue);
 	m_szBuffer[max_dump-1]=_t('\0');
 	MLOCK(m_lock);
 	*m_pBuffer+=m_szBuffer;
Index: ext/libicpf/src/libicpf/err_codes.h
===================================================================
diff -u -rb337c059691a6940b52a86388ff427c734be8eb6 -r361d7f8b9268e18f39e298ea82425f7ddb24fb43
--- ext/libicpf/src/libicpf/err_codes.h	(.../err_codes.h)	(revision b337c059691a6940b52a86388ff427c734be8eb6)
+++ ext/libicpf/src/libicpf/err_codes.h	(.../err_codes.h)	(revision 361d7f8b9268e18f39e298ea82425f7ddb24fb43)
@@ -96,4 +96,10 @@
 /// Error in converting a hex string to the binary data
 #define CE_HEX2BIN						(CE_BASE+0x0000)
 
+////////////////////////////////////////////////////////////////////
+// general
+#define GE_BASE							0x00040000
+/// Invalid argument passed to the function
+#define GE_INVALIDARG					(GE_BASE + 0x0000)
+
 #endif
Index: ext/libicpf/src/libicpf/file.cpp
===================================================================
diff -u -rb337c059691a6940b52a86388ff427c734be8eb6 -r361d7f8b9268e18f39e298ea82425f7ddb24fb43
--- ext/libicpf/src/libicpf/file.cpp	(.../file.cpp)	(revision b337c059691a6940b52a86388ff427c734be8eb6)
+++ ext/libicpf/src/libicpf/file.cpp	(.../file.cpp)	(revision 361d7f8b9268e18f39e298ea82425f7ddb24fb43)
@@ -685,6 +685,8 @@
 {
 	// make sure everything is ok
 	assert(m_bSerializing && m_pbySerialBuffer != NULL);
+	if(!m_pbySerialBuffer)
+		THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0);
 
 	// check the operation type
 	if ((m_uiFlags & FA_READ) && (m_uiFlags & FA_WRITE))
@@ -956,6 +958,8 @@
 uint_t file::_read_packet()
 {
 	assert(m_hFile);
+	if(!m_hFile || !m_pbyBuffer)
+		THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0);
 
 	// read data
 #ifdef _WIN32
@@ -981,6 +985,8 @@
 uint_t file::_write_packet()
 {
 	assert(m_hFile);
+	if(!m_hFile || !m_pbyBuffer)
+		THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0);
 
 #ifdef _WIN32
 	DWORD wr=0;
Index: ext/libicpf/src/libicpf/libicpf.vc90.vcproj
===================================================================
diff -u -rf59b3a0da37558c2af6b13a6a88ed16196c05832 -r361d7f8b9268e18f39e298ea82425f7ddb24fb43
--- ext/libicpf/src/libicpf/libicpf.vc90.vcproj	(.../libicpf.vc90.vcproj)	(revision f59b3a0da37558c2af6b13a6a88ed16196c05832)
+++ ext/libicpf/src/libicpf/libicpf.vc90.vcproj	(.../libicpf.vc90.vcproj)	(revision 361d7f8b9268e18f39e298ea82425f7ddb24fb43)
@@ -358,6 +358,7 @@
 			/>
 			<Tool
 				Name="VCCLCompilerTool"
+				AdditionalOptions="/analyze"
 				Optimization="0"
 				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE"
 				MinimalRebuild="true"
Index: ext/libicpf/src/libicpf/log.cpp
===================================================================
diff -u -rf1b06fb5cb28c288447c8aa69dccfca82179f6e7 -r361d7f8b9268e18f39e298ea82425f7ddb24fb43
--- ext/libicpf/src/libicpf/log.cpp	(.../log.cpp)	(revision f1b06fb5cb28c288447c8aa69dccfca82179f6e7)
+++ ext/libicpf/src/libicpf/log.cpp	(.../log.cpp)	(revision 361d7f8b9268e18f39e298ea82425f7ddb24fb43)
@@ -103,6 +103,8 @@
 int_t log_file::size() const
 {
 	assert(m_pszPath);
+	if(!m_pszPath)
+		return -1;
 	
 	int_t iSize=-1;
 	FILE* pFile=_tfopen(m_pszPath, _t("r"));
@@ -126,7 +128,9 @@
 bool log_file::truncate(int_t iAdd) const
 {
 	assert(m_pszPath);
-	
+	if(!m_pszPath)
+		return false;
+
 	// if we doesn't need to truncate anything
 	if (m_iMaxSize <= 0)
 		return true;
@@ -296,9 +300,11 @@
 void log_file::logs(int_t iType, bool bStd, const tchar_t* pszStr)
 {
 	assert(m_pszPath);
-	
-	if (iType < m_iLogLevel)
+	if(!m_pszPath)
 		return;
+
+	if (iType < m_iLogLevel || iType < 0 || iType >= sizeof(__logtype_str))
+		return;
 	
 	// log time
 	time_t t=time(NULL);
@@ -571,7 +577,8 @@
 
 		// format a string with err no and desc
 		tchar_t szError[1024];
-		_sntprintf(szError, 1024, _t("0x%lx (%s)"), iSysErr, pszErrDesc);
+		_sntprintf(szError, 1023, _t("0x%lx (%s)"), iSysErr, pszErrDesc);
+		szError[1023] = _T('\0');
 
 		// replace %err with the new data
 		pszOut[0]=_t('\0');