Merge pull request #6466 from akallabeth/memsan

Memsan: fixes (most) unit tests for use with memory sanitizer
This commit is contained in:
Martin Fleisz 2020-10-28 09:46:12 +01:00 committed by GitHub
commit 7be04e212b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 64 additions and 46 deletions

View File

@ -1887,9 +1887,9 @@ static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context)
if ((xfc->_NET_SUPPORTED != None) && (xfc->_NET_SUPPORTING_WM_CHECK != None)) if ((xfc->_NET_SUPPORTED != None) && (xfc->_NET_SUPPORTING_WM_CHECK != None))
{ {
Atom actual_type; Atom actual_type = 0;
int actual_format; int actual_format = 0;
unsigned long nitems, after; unsigned long nitems = 0, after = 0;
unsigned char* data = NULL; unsigned char* data = NULL;
int status = XGetWindowProperty(xfc->display, RootWindowOfScreen(xfc->screen), int status = XGetWindowProperty(xfc->display, RootWindowOfScreen(xfc->screen),
xfc->_NET_SUPPORTED, 0, 1024, False, XA_ATOM, &actual_type, xfc->_NET_SUPPORTED, 0, 1024, False, XA_ATOM, &actual_type,

View File

@ -36,9 +36,9 @@ static BOOL run_encode_decode_single(UINT16 bpp, BITMAP_INTERLEAVED_CONTEXT* enc
const size_t SrcSize = step * h; const size_t SrcSize = step * h;
const float maxDiff = 4.0f * ((bpp < 24) ? 2.0f : 1.0f); const float maxDiff = 4.0f * ((bpp < 24) ? 2.0f : 1.0f);
UINT32 DstSize = SrcSize; UINT32 DstSize = SrcSize;
BYTE* pSrcData = malloc(SrcSize); BYTE* pSrcData = calloc(1, SrcSize);
BYTE* pDstData = malloc(SrcSize); BYTE* pDstData = calloc(1, SrcSize);
BYTE* tmp = malloc(SrcSize); BYTE* tmp = calloc(1, SrcSize);
if (!pSrcData || !pDstData || !tmp) if (!pSrcData || !pDstData || !tmp)
goto fail; goto fail;

View File

@ -420,7 +420,7 @@ rdpSettings* freerdp_settings_new(DWORD flags)
settings->AllowCacheWaitingList = TRUE; settings->AllowCacheWaitingList = TRUE;
settings->BitmapCacheV2NumCells = 5; settings->BitmapCacheV2NumCells = 5;
settings->BitmapCacheV2CellInfo = settings->BitmapCacheV2CellInfo =
(BITMAP_CACHE_V2_CELL_INFO*)malloc(sizeof(BITMAP_CACHE_V2_CELL_INFO) * 6); (BITMAP_CACHE_V2_CELL_INFO*)calloc(6, sizeof(BITMAP_CACHE_V2_CELL_INFO));
if (!settings->BitmapCacheV2CellInfo) if (!settings->BitmapCacheV2CellInfo)
goto out_fail; goto out_fail;
@ -439,12 +439,12 @@ rdpSettings* freerdp_settings_new(DWORD flags)
settings->RefreshRect = TRUE; settings->RefreshRect = TRUE;
settings->SuppressOutput = TRUE; settings->SuppressOutput = TRUE;
settings->GlyphSupportLevel = GLYPH_SUPPORT_NONE; settings->GlyphSupportLevel = GLYPH_SUPPORT_NONE;
settings->GlyphCache = malloc(sizeof(GLYPH_CACHE_DEFINITION) * 10); settings->GlyphCache = calloc(10, sizeof(GLYPH_CACHE_DEFINITION));
if (!settings->GlyphCache) if (!settings->GlyphCache)
goto out_fail; goto out_fail;
settings->FragCache = malloc(sizeof(GLYPH_CACHE_DEFINITION)); settings->FragCache = calloc(1, sizeof(GLYPH_CACHE_DEFINITION));
if (!settings->FragCache) if (!settings->FragCache)
goto out_fail; goto out_fail;
@ -527,21 +527,21 @@ rdpSettings* freerdp_settings_new(DWORD flags)
settings->DeviceArraySize = 16; settings->DeviceArraySize = 16;
settings->DeviceArray = settings->DeviceArray =
(RDPDR_DEVICE**)calloc(1, sizeof(RDPDR_DEVICE*) * settings->DeviceArraySize); (RDPDR_DEVICE**)calloc(settings->DeviceArraySize, sizeof(RDPDR_DEVICE*));
if (!settings->DeviceArray) if (!settings->DeviceArray)
goto out_fail; goto out_fail;
settings->StaticChannelArraySize = 16; settings->StaticChannelArraySize = 16;
settings->StaticChannelArray = settings->StaticChannelArray =
(ADDIN_ARGV**)calloc(1, sizeof(ADDIN_ARGV*) * settings->StaticChannelArraySize); (ADDIN_ARGV**)calloc(settings->StaticChannelArraySize, sizeof(ADDIN_ARGV*));
if (!settings->StaticChannelArray) if (!settings->StaticChannelArray)
goto out_fail; goto out_fail;
settings->DynamicChannelArraySize = 16; settings->DynamicChannelArraySize = 16;
settings->DynamicChannelArray = settings->DynamicChannelArray =
(ADDIN_ARGV**)calloc(1, sizeof(ADDIN_ARGV*) * settings->DynamicChannelArraySize); (ADDIN_ARGV**)calloc(settings->DynamicChannelArraySize, sizeof(ADDIN_ARGV*));
if (!settings->DynamicChannelArray) if (!settings->DynamicChannelArray)
goto out_fail; goto out_fail;

View File

@ -147,13 +147,13 @@ static primitives_YUV_benchmark* primitives_YUV_benchmark_init(primitives_YUV_be
ret->outputStride = roi->width * 4; ret->outputStride = roi->width * 4;
ret->testedFormat = PIXEL_FORMAT_BGRA32; ret->testedFormat = PIXEL_FORMAT_BGRA32;
ret->outputBuffer = malloc(ret->outputStride * roi->height); ret->outputBuffer = calloc(ret->outputStride, roi->height);
if (!ret->outputBuffer) if (!ret->outputBuffer)
goto fail; goto fail;
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
{ {
BYTE* buf = ret->channels[i] = malloc(roi->width * roi->height); BYTE* buf = ret->channels[i] = calloc(roi->width, roi->height);
if (!buf) if (!buf)
goto fail; goto fail;
@ -172,7 +172,7 @@ static BOOL primitives_YUV_benchmark_run(primitives_YUV_benchmark* bench, primit
UINT64 runTime, UINT32* computations) UINT64 runTime, UINT32* computations)
{ {
ULONGLONG dueDate; ULONGLONG dueDate;
const BYTE* channels[3]; const BYTE* channels[3] = { 0 };
size_t i; size_t i;
pstatus_t status; pstatus_t status;

View File

@ -119,9 +119,9 @@ static BOOL check(const BYTE* pSrc1, UINT32 src1Step, const BYTE* pSrc2, UINT32
static BOOL test_alphaComp_func(void) static BOOL test_alphaComp_func(void)
{ {
pstatus_t status; pstatus_t status;
BYTE ALIGN(src1[SRC1_WIDTH * SRC1_HEIGHT * 4]); BYTE ALIGN(src1[SRC1_WIDTH * SRC1_HEIGHT * 4]) = { 0 };
BYTE ALIGN(src2[SRC2_WIDTH * SRC2_HEIGHT * 4]); BYTE ALIGN(src2[SRC2_WIDTH * SRC2_HEIGHT * 4]) = { 0 };
BYTE ALIGN(dst1[DST_WIDTH * DST_HEIGHT * 4]); BYTE ALIGN(dst1[DST_WIDTH * DST_HEIGHT * 4]) = { 0 };
UINT32* ptr; UINT32* ptr;
UINT32 i; UINT32 i;
winpr_RAND((BYTE*)src1, sizeof(src1)); winpr_RAND((BYTE*)src1, sizeof(src1));
@ -162,9 +162,9 @@ static BOOL test_alphaComp_func(void)
static int test_alphaComp_speed(void) static int test_alphaComp_speed(void)
{ {
BYTE ALIGN(src1[SRC1_WIDTH * SRC1_HEIGHT]); BYTE ALIGN(src1[SRC1_WIDTH * SRC1_HEIGHT]) = { 0 };
BYTE ALIGN(src2[SRC2_WIDTH * SRC2_HEIGHT]); BYTE ALIGN(src2[SRC2_WIDTH * SRC2_HEIGHT]) = { 0 };
BYTE ALIGN(dst1[DST_WIDTH * DST_HEIGHT]); BYTE ALIGN(dst1[DST_WIDTH * DST_HEIGHT]) = { 0 };
char testStr[256]; char testStr[256];
UINT32* ptr; UINT32* ptr;
UINT32 i; UINT32 i;
@ -192,6 +192,9 @@ static int test_alphaComp_speed(void)
int TestPrimitivesAlphaComp(int argc, char* argv[]) int TestPrimitivesAlphaComp(int argc, char* argv[])
{ {
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
prim_test_setup(FALSE); prim_test_setup(FALSE);
if (!test_alphaComp_func()) if (!test_alphaComp_func())

View File

@ -50,7 +50,8 @@ static BOOL test_and_32u_impl(const char* name, __andC_32u_t fkt, const UINT32*
static BOOL test_and_32u_func(void) static BOOL test_and_32u_func(void)
{ {
UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]), ALIGN(dst[FUNC_TEST_SIZE + 3]); UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]) = { 0 };
UINT32 ALIGN(dst[FUNC_TEST_SIZE + 3]) = { 0 };
winpr_RAND((BYTE*)src, sizeof(src)); winpr_RAND((BYTE*)src, sizeof(src));
@ -73,7 +74,8 @@ static BOOL test_and_32u_func(void)
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
static BOOL test_and_32u_speed(void) static BOOL test_and_32u_speed(void)
{ {
UINT32 ALIGN(src[MAX_TEST_SIZE + 3]), ALIGN(dst[MAX_TEST_SIZE + 3]); UINT32 ALIGN(src[MAX_TEST_SIZE + 3]) = { 0 };
UINT32 ALIGN(dst[MAX_TEST_SIZE + 3]) = { 0 };
winpr_RAND((BYTE*)src, sizeof(src)); winpr_RAND((BYTE*)src, sizeof(src));
@ -109,7 +111,8 @@ static BOOL check(const UINT32* src, const UINT32* dst, UINT32 size, UINT32 valu
static BOOL test_or_32u_func(void) static BOOL test_or_32u_func(void)
{ {
pstatus_t status; pstatus_t status;
UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]), ALIGN(dst[FUNC_TEST_SIZE + 3]); UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]) = { 0 };
UINT32 ALIGN(dst[FUNC_TEST_SIZE + 3]) = { 0 };
winpr_RAND((BYTE*)src, sizeof(src)); winpr_RAND((BYTE*)src, sizeof(src));
@ -133,7 +136,8 @@ static BOOL test_or_32u_func(void)
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
static BOOL test_or_32u_speed(void) static BOOL test_or_32u_speed(void)
{ {
UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]), ALIGN(dst[FUNC_TEST_SIZE + 3]); UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]) = { 0 };
UINT32 ALIGN(dst[FUNC_TEST_SIZE + 3]) = { 0 };
char testStr[256]; char testStr[256];
testStr[0] = '\0'; testStr[0] = '\0';
winpr_RAND((BYTE*)src, sizeof(src)); winpr_RAND((BYTE*)src, sizeof(src));
@ -147,6 +151,9 @@ static BOOL test_or_32u_speed(void)
int TestPrimitivesAndOr(int argc, char* argv[]) int TestPrimitivesAndOr(int argc, char* argv[])
{ {
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
prim_test_setup(FALSE); prim_test_setup(FALSE);
if (!test_and_32u_func()) if (!test_and_32u_func())

View File

@ -38,11 +38,11 @@ static BOOL test_RGBToRGB_16s8u_P3AC4R_func(prim_size_t roi, DWORD DstFormat)
PROFILER_DEFINE(optProf) PROFILER_DEFINE(optProf)
PROFILER_CREATE(genericProf, "RGBToRGB_16s8u_P3AC4R-GENERIC") PROFILER_CREATE(genericProf, "RGBToRGB_16s8u_P3AC4R-GENERIC")
PROFILER_CREATE(optProf, "RGBToRGB_16s8u_P3AC4R-OPTIMIZED") PROFILER_CREATE(optProf, "RGBToRGB_16s8u_P3AC4R-OPTIMIZED")
r = _aligned_malloc(rgbStride * roi.height, 16); r = _aligned_recalloc(NULL, 1, rgbStride * roi.height, 16);
g = _aligned_malloc(rgbStride * roi.height, 16); g = _aligned_recalloc(NULL, 1, rgbStride * roi.height, 16);
b = _aligned_malloc(rgbStride * roi.height, 16); b = _aligned_recalloc(NULL, 1, rgbStride * roi.height, 16);
out1 = _aligned_malloc(dstStride * roi.height, 16); out1 = _aligned_recalloc(NULL, 1, dstStride * roi.height, 16);
out2 = _aligned_malloc(dstStride * roi.height, 16); out2 = _aligned_recalloc(NULL, 1, dstStride * roi.height, 16);
if (!r || !g || !b || !out1 || !out2) if (!r || !g || !b || !out1 || !out2)
goto fail; goto fail;

View File

@ -25,9 +25,9 @@
static BOOL test_copy8u_func(void) static BOOL test_copy8u_func(void)
{ {
primitives_t* prims = primitives_get(); primitives_t* prims = primitives_get();
BYTE ALIGN(data[COPY_TESTSIZE + 15]); BYTE ALIGN(data[COPY_TESTSIZE + 15]) = { 0 };
int i, soff; int i, soff;
BYTE ALIGN(dest[COPY_TESTSIZE + 15]); BYTE ALIGN(dest[COPY_TESTSIZE + 15]) = { 0 };
winpr_RAND(data, sizeof(data)); winpr_RAND(data, sizeof(data));
for (soff = 0; soff < 16; ++soff) for (soff = 0; soff < 16; ++soff)

View File

@ -25,9 +25,9 @@
static BOOL test_sign16s_func(void) static BOOL test_sign16s_func(void)
{ {
pstatus_t status; pstatus_t status;
INT16 ALIGN(src[TEST_BUFFER_SIZE + 16]); INT16 ALIGN(src[TEST_BUFFER_SIZE + 16]) = { 0 };
INT16 ALIGN(d1[TEST_BUFFER_SIZE + 16]); INT16 ALIGN(d1[TEST_BUFFER_SIZE + 16]) = { 0 };
INT16 ALIGN(d2[TEST_BUFFER_SIZE + 16]); INT16 ALIGN(d2[TEST_BUFFER_SIZE + 16]) = { 0 };
winpr_RAND((BYTE*)src, sizeof(src)); winpr_RAND((BYTE*)src, sizeof(src));
memset(d1, 0, sizeof(d1)); memset(d1, 0, sizeof(d1));
memset(d2, 0, sizeof(d2)); memset(d2, 0, sizeof(d2));
@ -62,7 +62,8 @@ static BOOL test_sign16s_func(void)
static int test_sign16s_speed(void) static int test_sign16s_speed(void)
{ {
INT16 ALIGN(src[MAX_TEST_SIZE + 3]), ALIGN(dst[MAX_TEST_SIZE + 3]); INT16 ALIGN(src[MAX_TEST_SIZE + 3]) = { 0 };
INT16 ALIGN(dst[MAX_TEST_SIZE + 3]) = { 0 };
winpr_RAND((BYTE*)src, sizeof(src)); winpr_RAND((BYTE*)src, sizeof(src));
if (!speed_test("sign16s", "aligned", g_Iterations, (speed_test_fkt)generic->sign_16s, if (!speed_test("sign16s", "aligned", g_Iterations, (speed_test_fkt)generic->sign_16s,
@ -78,6 +79,9 @@ static int test_sign16s_speed(void)
int TestPrimitivesSign(int argc, char* argv[]) int TestPrimitivesSign(int argc, char* argv[])
{ {
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
prim_test_setup(FALSE); prim_test_setup(FALSE);
if (!test_sign16s_func()) if (!test_sign16s_func())

View File

@ -38,9 +38,9 @@ static BOOL test_YCoCgRToRGB_8u_AC4R_func(UINT32 width, UINT32 height)
PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 }; PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 };
PROFILER_DEFINE(genericProf) PROFILER_DEFINE(genericProf)
PROFILER_DEFINE(optProf) PROFILER_DEFINE(optProf)
in = _aligned_malloc(size, 16); in = _aligned_recalloc(NULL, 1, size, 16);
out_c = _aligned_malloc(size, 16); out_c = _aligned_recalloc(NULL, 1, size, 16);
out_sse = _aligned_malloc(size, 16); out_sse = _aligned_recalloc(NULL, 1, size, 16);
if (!in || !out_c || !out_sse) if (!in || !out_c || !out_sse)
goto fail; goto fail;
@ -111,6 +111,8 @@ fail:
int TestPrimitivesYCoCg(int argc, char* argv[]) int TestPrimitivesYCoCg(int argc, char* argv[])
{ {
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
prim_test_setup(FALSE); prim_test_setup(FALSE);
/* Random resolution tests */ /* Random resolution tests */

View File

@ -177,7 +177,7 @@ void* _aligned_offset_recalloc(void* memblock, size_t num, size_t size, size_t a
ZeroMemory(newMemblock, pNewMem->size); ZeroMemory(newMemblock, pNewMem->size);
} }
return memblock; return newMemblock;
} }
pMem = WINPR_ALIGNED_MEM_STRUCT_FROM_PTR(memblock); pMem = WINPR_ALIGNED_MEM_STRUCT_FROM_PTR(memblock);

View File

@ -151,7 +151,7 @@ BOOL CryptProtectMemory(LPVOID pData, DWORD cbData, DWORD dwFlags)
BYTE* pCipherText; BYTE* pCipherText;
size_t cbOut, cbFinal; size_t cbOut, cbFinal;
WINPR_CIPHER_CTX* enc = NULL; WINPR_CIPHER_CTX* enc = NULL;
BYTE randomKey[256]; BYTE randomKey[256] = { 0 };
WINPR_PROTECTED_MEMORY_BLOCK* pMemBlock; WINPR_PROTECTED_MEMORY_BLOCK* pMemBlock;
if (dwFlags != CRYPTPROTECTMEMORY_SAME_PROCESS) if (dwFlags != CRYPTPROTECTMEMORY_SAME_PROCESS)
@ -183,7 +183,7 @@ BOOL CryptProtectMemory(LPVOID pData, DWORD cbData, DWORD dwFlags)
SecureZeroMemory(randomKey, sizeof(randomKey)); SecureZeroMemory(randomKey, sizeof(randomKey));
cbOut = pMemBlock->cbData + 16 - 1; cbOut = pMemBlock->cbData + 16 - 1;
pCipherText = (BYTE*)malloc(cbOut); pCipherText = (BYTE*)calloc(1, cbOut);
if (!pCipherText) if (!pCipherText)
goto out; goto out;

View File

@ -215,7 +215,6 @@ LONG RegOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesire
{ {
Reg* reg; Reg* reg;
RegKey* pKey; RegKey* pKey;
reg = RegGetInstance(); reg = RegGetInstance();
if (!reg) if (!reg)

View File

@ -6,10 +6,13 @@ int TestSmartCardListReaders(int argc, char* argv[])
{ {
LONG lStatus; LONG lStatus;
LPSTR pReader; LPSTR pReader;
SCARDCONTEXT hSC; SCARDCONTEXT hSC = 0;
LPSTR mszReaders = NULL; LPSTR mszReaders = NULL;
DWORD cchReaders = SCARD_AUTOALLOCATE; DWORD cchReaders = SCARD_AUTOALLOCATE;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
lStatus = SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &hSC); lStatus = SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &hSC);
if (lStatus != SCARD_S_SUCCESS) if (lStatus != SCARD_S_SUCCESS)

View File

@ -414,7 +414,7 @@ BOOL GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
{ {
char* dot; char* dot;
size_t length; size_t length;
char hostname[256]; char hostname[256] = { 0 };
if (!lpnSize) if (!lpnSize)
{ {
@ -447,7 +447,7 @@ BOOL GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD lpnSize) BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD lpnSize)
{ {
size_t length; size_t length;
char hostname[256]; char hostname[256] = { 0 };
if (!lpnSize) if (!lpnSize)
{ {