本文整理汇总了C++中wmemset函数的典型用法代码示例。如果您正苦于以下问题:C++ wmemset函数的具体用法?C++ wmemset怎么用?C++ wmemset使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wmemset函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: goodG2B2
/* goodG2B2() - use goodsource and badsink by reversing the blocks in the if statement */
static void goodG2B2()
{
wchar_t * data;
wchar_t dataBadBuffer[50];
wchar_t dataGoodBuffer[100];
if(1)
{
/* FIX: Set a pointer to a "large" buffer, thus avoiding buffer overflows in the sinks. */
data = dataGoodBuffer;
data[0] = L'\0'; /* null terminate */
}
{
wchar_t source[100];
wmemset(source, L'C', 100-1); /* fill with L'C's */
source[100-1] = L'\0'; /* null terminate */
/* POTENTIAL FLAW: Possible buffer overflow if the size of data is less than the length of source */
wcsncpy(data, source, 100-1);
data[100-1] = L'\0'; /* Ensure the destination buffer is null terminated */
printWLine(data);
}
}
开发者ID:maurer,项目名称:tiamat,代码行数:22,代码来源:CWE121_Stack_Based_Buffer_Overflow__CWE805_wchar_t_declare_ncpy_02.c
示例2: CWE121_Stack_Based_Buffer_Overflow__CWE805_wchar_t_alloca_ncat_08_bad
void CWE121_Stack_Based_Buffer_Overflow__CWE805_wchar_t_alloca_ncat_08_bad()
{
wchar_t * data;
wchar_t * dataBadBuffer = (wchar_t *)ALLOCA(50*sizeof(wchar_t));
wchar_t * dataGoodBuffer = (wchar_t *)ALLOCA(100*sizeof(wchar_t));
if(staticReturnsTrue())
{
/* FLAW: Set a pointer to a "small" buffer. This buffer will be used in the sinks as a destination
* buffer in various memory copying functions using a "large" source buffer. */
data = dataBadBuffer;
data[0] = L'\0'; /* null terminate */
}
{
wchar_t source[100];
wmemset(source, L'C', 100-1); /* fill with L'C's */
source[100-1] = L'\0'; /* null terminate */
/* POTENTIAL FLAW: Possible buffer overflow if the sizeof(data)-strlen(data) is less than the length of source */
wcsncat(data, source, 100);
printWLine(data);
}
}
开发者ID:maurer,项目名称:tiamat,代码行数:21,代码来源:CWE121_Stack_Based_Buffer_Overflow__CWE805_wchar_t_alloca_ncat_08.c
示例3: CWE121_Stack_Based_Buffer_Overflow__CWE805_wchar_t_declare_snprintf_10_bad
void CWE121_Stack_Based_Buffer_Overflow__CWE805_wchar_t_declare_snprintf_10_bad()
{
wchar_t * data;
wchar_t dataBadBuffer[50];
wchar_t dataGoodBuffer[100];
if(globalTrue)
{
/* FLAW: Set a pointer to a "small" buffer. This buffer will be used in the sinks as a destination
* buffer in various memory copying functions using a "large" source buffer. */
data = dataBadBuffer;
data[0] = L'\0'; /* null terminate */
}
{
wchar_t source[100];
wmemset(source, L'C', 100-1); /* fill with L'C's */
source[100-1] = L'\0'; /* null terminate */
/* POTENTIAL FLAW: Possible buffer overflow if the size of data is less than the length of source */
SNPRINTF(data, 100, L"%s", source);
printWLine(data);
}
}
开发者ID:maurer,项目名称:tiamat,代码行数:21,代码来源:CWE121_Stack_Based_Buffer_Overflow__CWE805_wchar_t_declare_snprintf_10.c
示例4: goodG2B
/* goodG2B() uses the GoodSource with the BadSink */
static void goodG2B()
{
wchar_t * data;
wchar_t dataBadBuffer[50];
wchar_t dataGoodBuffer[100];
/* FIX: Set a pointer to a "large" buffer, thus avoiding buffer overflows in the sinks. */
data = dataGoodBuffer;
data[0] = L'\0'; /* null terminate */
{
wchar_t * dataCopy = data;
wchar_t * data = dataCopy;
{
wchar_t source[100];
wmemset(source, L'C', 100-1); /* fill with L'C's */
source[100-1] = L'\0'; /* null terminate */
/* POTENTIAL FLAW: Possible buffer overflow if the sizeof(data)-strlen(data) is less than the length of source */
wcscat(data, source);
printWLine(data);
}
}
}
开发者ID:maurer,项目名称:tiamat,代码行数:22,代码来源:CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_declare_cat_31.c
示例5: goodG2B2
/* goodG2B2() - use goodsource and badsink by reversing the blocks in the if statement */
static void goodG2B2()
{
wchar_t * data;
data = NULL;
if(5==5)
{
/* FIX: Allocate using new[] and point data to a large buffer that is at least as large as the large buffer used in the sink */
data = new wchar_t[100];
data[0] = L'\0'; /* null terminate */
}
{
wchar_t source[100];
wmemset(source, L'C', 100-1); /* fill with L'C's */
source[100-1] = L'\0'; /* null terminate */
/* POTENTIAL FLAW: Possible buffer overflow if source is larger than data */
memmove(data, source, 100*sizeof(wchar_t));
data[100-1] = L'\0'; /* Ensure the destination buffer is null terminated */
printWLine(data);
delete [] data;
}
}
开发者ID:maurer,项目名称:tiamat,代码行数:22,代码来源:CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_wchar_t_memmove_03.cpp
示例6: setlocale
//在Win32平台下,将GBK编码转换为UTF-8
string MyUtility::gbk_2_utf8(const string text)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
//采用Lambda表达式,将string转换成wstring
wstring tes = [=]() {
setlocale(LC_ALL, "chs");
const char* _Source = text.c_str();
size_t _Dsize = text.size() + 1;
wchar_t *_Dest = new wchar_t[_Dsize];
wmemset(_Dest, 0, _Dsize);
mbstowcs(_Dest,_Source,_Dsize);
std::wstring result = _Dest;
delete []_Dest;
setlocale(LC_ALL, "C");
return result;
}();
int asciSize = WideCharToMultiByte(CP_UTF8,0,tes.c_str(),tes.size(),NULL,0,NULL,NULL);
if (asciSize == ERROR_NO_UNICODE_TRANSLATION || asciSize == 0)
{
return string();
}
char *resultString = new char[asciSize];
int conveResult = WideCharToMultiByte(CP_UTF8,0,tes.c_str(),tes.size(),resultString,asciSize,NULL,NULL);
if (conveResult != asciSize)
{
return string();
}
string buffer = "";
buffer.append(resultString,asciSize);
delete[] resultString;
return buffer;
#else
return text;
#endif
}
示例7: bad
void bad()
{
wchar_t * data;
wchar_t * &dataRef = data;
wchar_t * dataBadBuffer = (wchar_t *)ALLOCA(50*sizeof(wchar_t));
wchar_t * dataGoodBuffer = (wchar_t *)ALLOCA(100*sizeof(wchar_t));
/* FLAW: Set a pointer to a "small" buffer. This buffer will be used in the sinks as a destination
* buffer in various memory copying functions using a "large" source buffer. */
data = dataBadBuffer;
data[0] = L'\0'; /* null terminate */
{
wchar_t * data = dataRef;
{
wchar_t source[100];
wmemset(source, L'C', 100-1); /* fill with L'C's */
source[100-1] = L'\0'; /* null terminate */
/* POTENTIAL FLAW: Possible buffer overflow if the size of data is less than the length of source */
wcscpy(data, source);
printWLine(data);
}
}
}
开发者ID:maurer,项目名称:tiamat,代码行数:22,代码来源:CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_alloca_cpy_33.cpp
示例8: CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_declare_cpy_17_bad
void CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_declare_cpy_17_bad()
{
int i;
wchar_t * data;
wchar_t dataBadBuffer[50];
wchar_t dataGoodBuffer[100];
for(i = 0; i < 1; i++)
{
/* FLAW: Set a pointer to a "small" buffer. This buffer will be used in the sinks as a destination
* buffer in various memory copying functions using a "large" source buffer. */
data = dataBadBuffer;
data[0] = L'\0'; /* null terminate */
}
{
wchar_t source[100];
wmemset(source, L'C', 100-1); /* fill with L'C's */
source[100-1] = L'\0'; /* null terminate */
/* POTENTIAL FLAW: Possible buffer overflow if the size of data is less than the length of source */
wcscpy(data, source);
printWLine(data);
}
}
开发者ID:maurer,项目名称:tiamat,代码行数:22,代码来源:CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_declare_cpy_17.c
示例9: goodG2B
/* goodG2B() uses the GoodSource with the BadSink */
static void goodG2B()
{
wchar_t * data;
CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_ncat_34_unionType myUnion;
data = NULL;
/* FIX: Allocate and point data to a large buffer that is at least as large as the large buffer used in the sink */
data = (wchar_t *)malloc(100*sizeof(wchar_t));
data[0] = L'\0'; /* null terminate */
myUnion.unionFirst = data;
{
wchar_t * data = myUnion.unionSecond;
{
wchar_t source[100];
wmemset(source, L'C', 100-1); /* fill with L'C's */
source[100-1] = L'\0'; /* null terminate */
/* POTENTIAL FLAW: Possible buffer overflow if source is larger than sizeof(data)-strlen(data) */
wcsncat(data, source, 100);
printWLine(data);
free(data);
}
}
}
示例10: strlen
char* CpeepmBrowser::GetCookie()
{
const char* http = "http://";
UINT len = strlen(http) + strlen(Server);
char* buffer = new char[len + 1];
ZeroMemory(buffer, len + 1);
strcat(buffer, http);
strcat(buffer, Server);
wchar_t* host = CpeepmUtil::CharToWideChar(buffer, len);
ReleaseArray(buffer);
if (host == NULL)
return NULL;
wchar_t tmp[1] = {0};
DWORD size = 0;
InternetGetCookie(host, NULL, tmp, &size);
if (size == 0)
{
ReleaseArray(host);
return NULL;
}
wchar_t* cookie = new wchar_t[size / 2 + 1];
wmemset(cookie, 0, size / 2 + 1);
InternetGetCookie(host, NULL, cookie, &size);
ReleaseArray(host);
len = wcslen(cookie);
if (len > 0)
{
char* c = CpeepmUtil::WideCharToChar(cookie, len);
ReleaseArray(cookie);
return c;
}
else
{
ReleaseArray(cookie);
return NULL;
}
}
示例11: wcslen
StringSearch_c::StringSearch_c ( const wchar_t * szPattern, bool bMatchCase, bool bWholeWord )
: m_iPatLen ( wcslen ( szPattern ) )
, m_iMin ( szPattern [0] )
, m_pFile ( NULL )
, m_bEndReached ( false )
, m_bMatchCase ( bMatchCase )
, m_bWholeWord ( bWholeWord )
, m_iNextOffset ( 0 )
{
Assert ( ! ( READ_BUFFER_SIZE & 1 ) );
Assert ( m_iPatLen < READ_BUFFER_SIZE );
m_iMax = m_iMin;
const wchar_t * szStart = szPattern;
while ( *szStart )
{
if ( *szStart > m_iMax )
m_iMax = *szStart;
else
if ( *szStart < m_iMin )
m_iMin = *szStart;
++szStart;
}
int iSize = m_iMax - m_iMin + 1;
m_dBadChar = new unsigned short [iSize];
wmemset ( (wchar_t*)m_dBadChar, m_iPatLen + 1, iSize );
m_szPattern = new wchar_t [ wcslen ( szPattern ) + 1 ];
wcscpy ( m_szPattern, szPattern );
if ( ! m_bMatchCase )
for ( int i = 0; i < m_iPatLen; ++i )
m_szPattern [i] = towlower ( m_szPattern [i] );
for ( int i = 0; i < m_iPatLen; ++i )
m_dBadChar [ szPattern [i] - m_iMin ] = m_iPatLen - i;
}
示例12: goodG2B
/* goodG2B() uses the GoodSource with the BadSink */
static void goodG2B()
{
wchar_t * data;
wchar_t * &dataRef = data;
wchar_t dataBuffer[100];
data = dataBuffer;
/* FIX: Properly initialize data */
data[0] = L'\0'; /* null terminate */
{
wchar_t * data = dataRef;
{
size_t sourceLen;
wchar_t source[100];
wmemset(source, L'C', 100-1); /* fill with L'C's */
source[100-1] = L'\0'; /* null terminate */
sourceLen = wcslen(source);
/* POTENTIAL FLAW: If data is not initialized properly, wcsncat() may not function correctly */
wcsncat(data, source, sourceLen);
printWLine(data);
}
}
}
示例13: bad
void bad()
{
wchar_t * data;
wchar_t * &dataRef = data;
wchar_t dataBuffer[100];
data = dataBuffer;
/* FLAW: Do not initialize data */
; /* empty statement needed for some flow variants */
{
wchar_t * data = dataRef;
{
size_t sourceLen;
wchar_t source[100];
wmemset(source, L'C', 100-1); /* fill with L'C's */
source[100-1] = L'\0'; /* null terminate */
sourceLen = wcslen(source);
/* POTENTIAL FLAW: If data is not initialized properly, wcsncat() may not function correctly */
wcsncat(data, source, sourceLen);
printWLine(data);
}
}
}
示例14: s2ws
std::wstring s2ws( const std::string& s )
{
#ifdef WIN_PLATFORM
setlocale(LC_ALL, "chs");
const char* _Source = s.c_str();
size_t _Dsize = s.size() + 1;
wchar_t *_Dest = new wchar_t[_Dsize];
wmemset(_Dest, 0, _Dsize);
mbstowcs(_Dest,_Source,_Dsize);
std::wstring result = _Dest;
delete []_Dest;
setlocale(LC_ALL, "C");
return result;
#endif
// wstring rt;
// return rt;
std::wstring val = L"";
if ( NULL == s.c_str() )
{
return val;
}
//size_t size_of_ch = strlen(pc)*sizeof(char);
//size_t size_of_wc = get_wchar_size(pc);
size_t size_of_wc;
size_t destlen = mbstowcs(0,s.c_str(),0);
if (destlen ==(size_t)(-1))
{
return val;
}
size_of_wc = destlen+1;
wchar_t *pw = new wchar_t[size_of_wc];
mbstowcs(pw,s.c_str(),size_of_wc);
val = pw;
delete pw;
return val;
}
示例15: good1
/* good1() uses if(GLOBAL_CONST_FIVE!=5) instead of if(GLOBAL_CONST_FIVE==5) */
static void good1()
{
if(GLOBAL_CONST_FIVE!=5)
{
/* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
printLine("Benign, fixed string");
}
else
{
{
wchar_t data[150], dest[100];
/* Initialize data */
wmemset(data, L'A', 149);
data[149] = L'\0';
/* wcsncpy() does not null terminate if the string in the src buffer is larger than
* the number of characters being copied to the dest buffer */
wcsncpy(dest, data, 99);
dest[99] = L'\0'; /* FIX: Explicitly null terminate dest after the use of wcsncpy() */
printWLine(dest);
}
}
}