WinUnit offers a unique approach to unit testing native (C/C++) code on Windows.
WinUnit was originally introduced in the article “Simplified Unit Testing for Native C Applications” by Maria Blees in the February 2008 issue of MSDN Magazine. Click here to read the article and learn more about WinUnit.
Features:
- One executable which runs tests in separate DLLs
- One header file to make writing tests easier
- Logger extensibility
- Easy to automate
- Macros for use in Visual Studio
Note: This paper is derived from the book The Security Development Lifecycle, by Michael Howard and Steve Lipner, Microsoft Press, 2006.
Prohibiting the use of banned APIs is a good way to remove a significant number of code vulnerabilities — this practice is reflected in Stage 6 of The Microsoft Security Development Lifecycle: “Establish and Follow Best Practices for Development.” It can also be referenced in Chapter 11 of the Microsoft Press Book The Security Development Lifecycle.
When the C runtime library (CRT) was first created about 25 years ago, the threats to computers were different; machines were not as interconnected as they are today, and attacks were not as prevalent. With this in mind, a subset of the C runtime library must be deprecated for new code and, over time, removed from earlier code. It’s just too easy to get code wrong that uses these outdated functions. Even some of the classic replacement functions are prone to error, too.
This list is the SDL view of what comprises banned APIs; it is derived from experience with real-world security bugs and focuses almost exclusively on functions that can lead to buffer overruns (Howard, LeBlanc, and Viega 2005). Any function in this section’s tables must be replaced with a more secure version. Obviously, you cannot replace a banned API with another banned API. For example, replacing strcpy with strncpy is not valid because strncpy is banned, too.
Also note that some of the function names might be a little different, depending on whether the function takes ASCII, Unicode, _T (ASCII or Unicode), or multibyte chars. Some function names might include A or W at the end of the name. For example, the StrSafe StringCbCatEx function is also available as StringCbCatExW (Unicode) and StringCbCatExA (ASCII).
More info
Сортировка слиянием (англ. merge sort) — алгоритм сортировки, который упорядочивает списки (или другие структуры данных, доступ к элементам которых можно получать только последовательно, например — потоки) в определённом порядке. Эта сортировка — хороший пример использования принципа «разделяй и властвуй». Сначала задача разбивается на несколько подзадач меньшего размера. Затем эти задачи решаются с помощью рекурсивного вызова или непосредственно, если их размер достаточно мал. Наконец, их решения комбинируются, и получается решение исходной задачи.
подробнее
Пирамидальная сортировка — алгоритм сортировки, работающий в худшем, в среднем и в лучшем случае (то есть гарантированно) за Θ(n log n) операций при сортировке n элементов. Количество применяемой служебной памяти не зависит от размера массива (то есть, O(1)).
Может рассматриватъся как усовершенствованная Bubblesort, в которой элемент всплывает (min-heap) / тонет (max-heap) по многим путям.
подробнее
class COverload
{
public:
COverload(int p) : m_intValue(p)
{ std::cout << "COverload::COverload() " << m_intValue << std::endl; };
virtual ~COverload()
{ std::cout << "COverload::~COverload()" << std::endl; };
public:
void overload(void)
{ std::cout << "COverload::overload() " << ++m_intValue << std::endl; };
void overload(void) const
{ std::cout << "COverload::overload() const " << m_intValue << std::endl; };
protected:
int m_intValue;
};
int main(void)
{
COverload const dd(2);
dd.overload();
COverload bb(3);
bb.overload();
}
Модель данных в С++ – это соотношения размерностей типов, принятых в рамках среды разработки.
Read more…
// Example 1
// Allocation
T* pv = (T*)malloc( sizeof(T) );
// Construction
::new( pv ) T( /*arg-list*/ );
...
// Destruction
pv->T::~T();
// Deallocation
free( pv );
// Example 2
class Blanks
{
public:
Blanks(){}
void* operator new( size_t stAllocateBlock, int chInit )
{
void* pvTemp = malloc( stAllocateBlock );
if( pvTemp != 0 )
{
memset( pvTemp, chInit, stAllocateBlock );
}
return pvTemp;
}
};
// For discrete objects of type Blanks, the global operator new function
// is hidden. Therefore, the following code allocates an object of type
// Blanks and initializes it to 0xa5
Blanks *a5 = new(0xa5) Blanks;
bool b = a5 != 0;