Commit 716a42e9 authored by Markus Kauppila's avatar Markus Kauppila

Added functions that generate random boundary values

for Uint16, Uint32 and Uint64 to the fuzzer.
parent e45c8d75
......@@ -137,12 +137,14 @@ RandomIntegerInRange(Sint32 pMin, Sint32 pMax)
* If boundary2 < boundary1, the values are swapped.
* If boundary1 == boundary2, value of boundary1 will be returned
*
* Generating boundary values for Uint8
* Generating boundary values for Uint8:
* BoundaryValues(sizeof(Uint8), 10, 20, True) -> [10,11,19,20]
* BoundaryValues(sizeof(Uint8), 10, 20, False) -> [9,21]
* BoundaryValues(sizeof(Uint8), 0, 15, True) -> [0, 1, 14, 15]
* BoundaryValues(sizeof(Uint8), 0, 15, False) -> [16]
* BoundaryValues(sizeof(Uint8), 0, 255, False) -> []
* BoundaryValues(sizeof(Uint8), 0, 255, False) -> NULL
*
* Generator works the same for other types of unsigned integers.
*
* \param maxValue The biggest value that is acceptable for this data type.
* For instance, for Uint8 -> 255, Uint16 -> 65536 etc.
......@@ -154,7 +156,6 @@ RandomIntegerInRange(Sint32 pMin, Sint32 pMax)
* \param outBufferSize Size of outBuffer
*
* \returns NULL on error, outBuffer on success
*
*/
Uint64 *
GenerateUnsignedBoundaryValues(const Uint64 maxValue,
......@@ -183,17 +184,19 @@ GenerateUnsignedBoundaryValues(const Uint64 maxValue,
}
else if(validDomain) {
tempBuf[index++] = boundary1;
tempBuf[index++] = boundary1 + 1;
if(boundary1 < UINT64_MAX)
tempBuf[index++] = boundary1 + 1;
tempBuf[index++] = boundary2 - 1;
tempBuf[index++] = boundary2;
}
else {
if(boundary1 != 0) {
if(boundary1 > 0) {
tempBuf[index++] = boundary1 - 1;
}
if(boundary2 != maxValue) {
if(boundary2 < maxValue) {
tempBuf[index++] = boundary2 + 1;
}
}
......@@ -223,13 +226,13 @@ RandomUint8BoundaryValue(Uint8 boundary1, Uint8 boundary2, SDL_bool validDomain)
Uint32 size;
// max value for Uint8
const Uint64 maxValue = 255;
const Uint64 maxValue = UINT8_MAX;
buffer = GenerateUnsignedBoundaryValues(maxValue,
(Uint64) boundary1, (Uint64) boundary2,
validDomain, buffer, &size);
if(buffer == NULL) {
return 0; // Change to some better error value? What would be better?
return -1; // Change to some better error value? What would be better?
}
Uint32 index = RandomInteger() % size;
......@@ -240,6 +243,77 @@ RandomUint8BoundaryValue(Uint8 boundary1, Uint8 boundary2, SDL_bool validDomain)
return retVal;
}
Uint16
RandomUint16BoundaryValue(Uint16 boundary1, Uint16 boundary2, SDL_bool validDomain)
{
Uint64 *buffer = NULL;
Uint32 size;
// max value for Uint16
const Uint64 maxValue = UINT16_MAX;
buffer = GenerateUnsignedBoundaryValues(maxValue,
(Uint64) boundary1, (Uint64) boundary2,
validDomain, buffer, &size);
if(buffer == NULL) {
return -1; // Change to some better error value? What would be better?
}
Uint32 index = RandomInteger() % size;
Uint16 retVal = (Uint16) buffer[index];
SDL_free(buffer);
return retVal;
}
Uint32
RandomUint32BoundaryValue(Uint32 boundary1, Uint32 boundary2, SDL_bool validDomain)
{
Uint64 *buffer = NULL;
Uint32 size;
// max value for Uint32
const Uint64 maxValue = UINT32_MAX;
buffer = GenerateUnsignedBoundaryValues(maxValue,
(Uint64) boundary1, (Uint64) boundary2,
validDomain, buffer, &size);
if(buffer == NULL) {
return -1; // Change to some better error value? What would be better?
}
Uint32 index = RandomInteger() % size;
Uint32 retVal = (Uint32) buffer[index];
SDL_free(buffer);
return retVal;
}
Uint64
RandomUint64BoundaryValue(Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
{
Uint64 *buffer = NULL;
Uint32 size;
// max value for Uint64
const Uint64 maxValue = UINT64_MAX;
buffer = GenerateUnsignedBoundaryValues(maxValue,
(Uint64) boundary1, (Uint64) boundary2,
validDomain, buffer, &size);
if(buffer == NULL) {
return -1; // Change to some better error value? What would be better?
}
Uint32 index = RandomInteger() % size;
Uint64 retVal = (Uint64) buffer[index];
SDL_free(buffer);
return retVal;
}
Sint8
RandomSint8BoundaryValue()
......
......@@ -61,6 +61,22 @@ Uint32 RandomPositiveInteger();
*/
Uint8 RandomUint8BoundaryValue(Uint8 boundary1, Uint8 boundary2, SDL_bool validDomain);
/*!
* todo add markup
*/
Uint16 RandomUint16BoundaryValue(Uint16 boundary1, Uint16 boundary2, SDL_bool validDomain);
/*!
* todo add markup
*/
Uint32 RandomUint32BoundaryValue(Uint32 boundary1, Uint32 boundary2, SDL_bool validDomain);
/*!
* todo add markup
*/
Uint64 RandomUint64BoundaryValue(Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain);
/*!
* todo add markup
......
......@@ -25,6 +25,7 @@
*/
#include <stdio.h>
#include <stdint.h>
#include <SDL/SDL.h>
......@@ -96,13 +97,16 @@ dummycase1(void *arg)
Log(0, "uint8 (same value): %u", RandomPositiveInteger());
// */
//Log(0, "uint8 (same value): %d", RandomUint8BoundaryValue(200, 200, SDL_TRUE));
Uint64 longlong = UINT64_MAX;
//printf("max: %llu", longlong);
for(; 1 ;) {
Log(0, "uint8: %u", RandomUint8BoundaryValue(10, 20, SDL_FALSE));
//Log(0, "int8: %d", RandomInt8BoundaryValue());
//Log(0, "int8: %u", RandomUint8BoundaryValue(0, 255, SDL_FALSE));
//Log(0, "uint16: %u", RandomUint16BoundaryValue(0, UINT16_MAX, SDL_FALSE));
//Log(0, "int32: %u", RandomUint32BoundaryValue(0, 0xFFFFFFFE, SDL_FALSE));
Log(0, "int64: %llu", RandomUint64BoundaryValue(2, 0xFFFFFFFFFFFFFFFE, SDL_FALSE));
}
for(; 0 ;) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment