[warnings] replace rand() function use
This commit is contained in:
parent
bd637c6cd1
commit
ba9897f8b7
@ -5757,7 +5757,7 @@ static BOOL FuzzPlanar(void)
|
||||
", nDstHeight=%" PRIu32 ", nDstStep=%" PRIu32 ", total size=%" PRIuz "\n",
|
||||
FreeRDPGetColorFormatName(DstFormat), nXDst, nYDst, nDstWidth, nDstHeight, nDstStep,
|
||||
sizeof(dstData));
|
||||
freerdp_planar_switch_bgr(planar, rand() % 2);
|
||||
freerdp_planar_switch_bgr(planar, prand(2) % 2);
|
||||
planar_decompress(planar, data, dataSize, prand(4096), prand(4096), dstData, DstFormat,
|
||||
nDstStep, nXDst, nYDst, nDstWidth, nDstHeight, prand(2));
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <freerdp/gdi/bitmap.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
|
||||
#include "line.h"
|
||||
#include "brush.h"
|
||||
@ -324,6 +325,13 @@ fail:
|
||||
return rc;
|
||||
}
|
||||
|
||||
static BYTE prand(void)
|
||||
{
|
||||
BYTE tmp = 0;
|
||||
winpr_RAND(&tmp, sizeof(tmp));
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static BOOL test_gdi_GetPixel(void)
|
||||
{
|
||||
BOOL rc = TRUE;
|
||||
@ -360,7 +368,7 @@ static BOOL test_gdi_GetPixel(void)
|
||||
{
|
||||
UINT32 pixel = 0;
|
||||
const UINT32 color =
|
||||
FreeRDPGetColor(hBitmap->format, rand(), rand(), rand(), rand());
|
||||
FreeRDPGetColor(hBitmap->format, prand(), prand(), prand(), prand());
|
||||
FreeRDPWriteColor(&hBitmap->data[i * hBitmap->scanline + j * bpp], hBitmap->format,
|
||||
color);
|
||||
pixel = gdi_GetPixel(hdc, j, i);
|
||||
@ -412,7 +420,7 @@ static BOOL test_gdi_SetPixel(void)
|
||||
{
|
||||
UINT32 pixel = 0;
|
||||
const UINT32 color =
|
||||
FreeRDPGetColor(hBitmap->format, rand(), rand(), rand(), rand());
|
||||
FreeRDPGetColor(hBitmap->format, prand(), prand(), prand(), prand());
|
||||
gdi_SetPixel(hdc, j, i, color);
|
||||
pixel = FreeRDPReadColor(&hBitmap->data[i * hBitmap->scanline + j * bpp],
|
||||
hBitmap->format);
|
||||
|
@ -687,6 +687,15 @@ static BOOL compare_yuv420(BYTE** planesA, BYTE** planesB, UINT32 width, UINT32
|
||||
return rc;
|
||||
}
|
||||
|
||||
static UINT32 prand(UINT32 max)
|
||||
{
|
||||
UINT32 tmp = 0;
|
||||
if (max <= 1)
|
||||
return 1;
|
||||
winpr_RAND(&tmp, sizeof(tmp));
|
||||
return tmp % (max - 1) + 1;
|
||||
}
|
||||
|
||||
static BOOL TestPrimitiveRgbToLumaChroma(primitives_t* prims, prim_size_t roi, UINT32 version)
|
||||
{
|
||||
BOOL res = FALSE;
|
||||
@ -772,10 +781,10 @@ static BOOL TestPrimitiveRgbToLumaChroma(primitives_t* prims, prim_size_t roi, U
|
||||
for (UINT32 x = 0; x < roi.width; x++)
|
||||
{
|
||||
#if 1
|
||||
line[x * 4 + 0] = rand();
|
||||
line[x * 4 + 1] = rand();
|
||||
line[x * 4 + 2] = rand();
|
||||
line[x * 4 + 3] = rand();
|
||||
line[x * 4 + 0] = prand(UINT8_MAX);
|
||||
line[x * 4 + 1] = prand(UINT8_MAX);
|
||||
line[x * 4 + 2] = prand(UINT8_MAX);
|
||||
line[x * 4 + 3] = prand(UINT8_MAX);
|
||||
#else
|
||||
line[x * 4 + 0] = (y * roi.width + x) * 16 + 5;
|
||||
line[x * 4 + 1] = (y * roi.width + x) * 16 + 7;
|
||||
|
@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
#include <winpr/wlog.h>
|
||||
#include <winpr/synch.h>
|
||||
#include <winpr/thread.h>
|
||||
@ -31,6 +32,15 @@ static int status = 0;
|
||||
static LONG* pLoopCount = NULL;
|
||||
static BOOL bStopTest = FALSE;
|
||||
|
||||
static UINT32 prand(UINT32 max)
|
||||
{
|
||||
UINT32 tmp = 0;
|
||||
if (max <= 1)
|
||||
return 1;
|
||||
winpr_RAND(&tmp, sizeof(tmp));
|
||||
return tmp % (max - 1) + 1;
|
||||
}
|
||||
|
||||
static DWORD WINAPI test_error_thread(LPVOID arg)
|
||||
{
|
||||
int id = 0;
|
||||
@ -41,7 +51,7 @@ static DWORD WINAPI test_error_thread(LPVOID arg)
|
||||
|
||||
do
|
||||
{
|
||||
dwErrorSet = (DWORD)abs(rand()) + 1;
|
||||
dwErrorSet = prand(UINT32_MAX - 1) + 1;
|
||||
SetLastError(dwErrorSet);
|
||||
if ((dwErrorGet = GetLastError()) != dwErrorSet)
|
||||
{
|
||||
|
@ -3,9 +3,19 @@
|
||||
#include <time.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
#include <winpr/file.h>
|
||||
#include <winpr/path.h>
|
||||
|
||||
static UINT32 prand(UINT32 max)
|
||||
{
|
||||
UINT32 tmp = 0;
|
||||
if (max <= 1)
|
||||
return 1;
|
||||
winpr_RAND(&tmp, sizeof(tmp));
|
||||
return tmp % (max - 1) + 1;
|
||||
}
|
||||
|
||||
int TestPathMakePath(int argc, char* argv[])
|
||||
{
|
||||
size_t baseLen = 0;
|
||||
@ -26,11 +36,10 @@ int TestPathMakePath(int argc, char* argv[])
|
||||
}
|
||||
|
||||
baseLen = strlen(base);
|
||||
srand(time(NULL));
|
||||
|
||||
for (int x = 0; x < 5; x++)
|
||||
{
|
||||
(void)sprintf_s(tmp, ARRAYSIZE(tmp), "%08X", rand());
|
||||
(void)sprintf_s(tmp, ARRAYSIZE(tmp), "%08" PRIX32, prand(UINT32_MAX));
|
||||
path = GetCombinedPath(base, tmp);
|
||||
free(base);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
#include <winpr/synch.h>
|
||||
#include <winpr/thread.h>
|
||||
#include <winpr/interlocked.h>
|
||||
@ -22,6 +23,15 @@ struct test_params
|
||||
DWORD flags;
|
||||
};
|
||||
|
||||
static UINT32 prand(UINT32 max)
|
||||
{
|
||||
UINT32 tmp = 0;
|
||||
if (max <= 1)
|
||||
return 1;
|
||||
winpr_RAND(&tmp, sizeof(tmp));
|
||||
return tmp % (max - 1) + 1;
|
||||
}
|
||||
|
||||
static DWORD WINAPI test_synch_barrier_thread(LPVOID lpParam)
|
||||
{
|
||||
BOOL status = FALSE;
|
||||
@ -43,7 +53,7 @@ static DWORD WINAPI test_synch_barrier_thread(LPVOID lpParam)
|
||||
for (DWORD i = 0; i < p->loops && gErrorCount == 0; i++)
|
||||
{
|
||||
/* simulate different execution times before the barrier */
|
||||
Sleep(1 + abs((rand() % MAX_SLEEP_MS)));
|
||||
Sleep(1 + prand(MAX_SLEEP_MS));
|
||||
status = EnterSynchronizationBarrier(&gBarrier, p->flags);
|
||||
|
||||
// printf("Thread #%03u status: %s\n", tnum, status ? "TRUE" : "FALSE");
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
#include <winpr/windows.h>
|
||||
#include <winpr/synch.h>
|
||||
#include <winpr/sysinfo.h>
|
||||
@ -40,6 +41,15 @@ static BOOL TestSynchCritical_TriggerAndCheckRaceCondition(HANDLE OwningThread,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static UINT32 prand(UINT32 max)
|
||||
{
|
||||
UINT32 tmp = 0;
|
||||
if (max <= 1)
|
||||
return 1;
|
||||
winpr_RAND(&tmp, sizeof(tmp));
|
||||
return tmp % (max - 1) + 1;
|
||||
}
|
||||
|
||||
/* this thread function shall increment the global dwTestValue until the PBOOL passsed in arg is
|
||||
* FALSE */
|
||||
static DWORD WINAPI TestSynchCritical_Test1(LPVOID arg)
|
||||
@ -59,14 +69,14 @@ static DWORD WINAPI TestSynchCritical_Test1(LPVOID arg)
|
||||
return 1;
|
||||
|
||||
/* add some random recursion level */
|
||||
int j = rand() % 5;
|
||||
for (int i = 0; i < j; i++)
|
||||
UINT32 j = prand(5);
|
||||
for (UINT32 i = 0; i < j; i++)
|
||||
{
|
||||
if (!TestSynchCritical_TriggerAndCheckRaceCondition(hThread, rc++))
|
||||
return 2;
|
||||
EnterCriticalSection(&critical);
|
||||
}
|
||||
for (int i = 0; i < j; i++)
|
||||
for (UINT32 i = 0; i < j; i++)
|
||||
{
|
||||
if (!TestSynchCritical_TriggerAndCheckRaceCondition(hThread, rc--))
|
||||
return 2;
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
#include <winpr/synch.h>
|
||||
#include <winpr/thread.h>
|
||||
#include <winpr/interlocked.h>
|
||||
@ -15,6 +16,15 @@ static LONG* pTestThreadFunctionCalls = NULL;
|
||||
static LONG* pTestOnceFunctionCalls = NULL;
|
||||
static LONG* pInitOnceExecuteOnceCalls = NULL;
|
||||
|
||||
static UINT32 prand(UINT32 max)
|
||||
{
|
||||
UINT32 tmp = 0;
|
||||
if (max <= 1)
|
||||
return 1;
|
||||
winpr_RAND(&tmp, sizeof(tmp));
|
||||
return tmp % (max - 1) + 1;
|
||||
}
|
||||
|
||||
static BOOL CALLBACK TestOnceFunction(PINIT_ONCE once, PVOID param, PVOID* context)
|
||||
{
|
||||
LONG calls = InterlockedIncrement(pTestOnceFunctionCalls) - 1;
|
||||
@ -24,7 +34,7 @@ static BOOL CALLBACK TestOnceFunction(PINIT_ONCE once, PVOID param, PVOID* conte
|
||||
WINPR_UNUSED(context);
|
||||
|
||||
/* simulate execution time */
|
||||
Sleep(30 + rand() % 40);
|
||||
Sleep(30 + prand(40));
|
||||
|
||||
if (calls < TEST_NUM_FAILURES)
|
||||
{
|
||||
|
@ -2,14 +2,24 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
#include <winpr/synch.h>
|
||||
#include <winpr/thread.h>
|
||||
|
||||
#define THREADS 8
|
||||
|
||||
static UINT32 prand(UINT32 max)
|
||||
{
|
||||
UINT32 tmp = 0;
|
||||
if (max <= 1)
|
||||
return 1;
|
||||
winpr_RAND(&tmp, sizeof(tmp));
|
||||
return tmp % (max - 1) + 1;
|
||||
}
|
||||
|
||||
static DWORD WINAPI test_thread(LPVOID arg)
|
||||
{
|
||||
long timeout = 50 + (rand() % 100);
|
||||
UINT32 timeout = 50 + prand(100);
|
||||
WINPR_UNUSED(arg);
|
||||
Sleep(timeout);
|
||||
ExitThread(0);
|
||||
|
Loading…
Reference in New Issue
Block a user