Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
dc97e62c
Commit
dc97e62c
authored
Aug 09, 2011
by
Markus Kauppila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added boundary value generator functions for Sint8,
Sint16, Sint32 and Sint64.
parent
49879f48
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
204 additions
and
6 deletions
+204
-6
fuzzer.c
test/test-automation/src/libSDLtest/fuzzer/fuzzer.c
+184
-3
fuzzer.h
test/test-automation/src/libSDLtest/fuzzer/fuzzer.h
+20
-3
No files found.
test/test-automation/src/libSDLtest/fuzzer/fuzzer.c
View file @
dc97e62c
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <limits.h>
#include "../../../include/SDL_test.h"
#include "../../../include/SDL_test.h"
...
@@ -318,12 +319,192 @@ RandomUint64BoundaryValue(Uint64 boundary1, Uint64 boundary2, SDL_bool validDoma
...
@@ -318,12 +319,192 @@ RandomUint64BoundaryValue(Uint64 boundary1, Uint64 boundary2, SDL_bool validDoma
return
retVal
;
return
retVal
;
}
}
/*!
* Generates boundary values between the given boundaries.
* Boundary values are inclusive. See the examples below.
* If boundary2 < boundary1, the values are swapped.
* If boundary1 == boundary2, value of boundary1 will be returned
*
* Generating boundary values for Sint8:
* <Add examples>
*
* Generator works the same for other types of signed integers.
*
* \paran minValue The smallest value that is acceptable for this data type.
* For instance, for Uint8 -> -128, Uint16 -> -32,768 etc.
* \param maxValue The biggest value that is acceptable for this data type.
* For instance, for Uint8 -> 127, Uint16 -> 32767 etc.
* \param pBoundary1 defines lower boundary
* \param pBoundary2 defines upper boundary
* \param validDomain Generate only for valid domain (for the data type)
*
* \param outBuffer The generated boundary values are put here
* \param outBufferSize Size of outBuffer
*
* \returns NULL on error, outBuffer on success
*/
Uint64
*
GenerateSignedBoundaryValues
(
const
Sint64
minValue
,
const
Sint64
maxValue
,
Sint64
pBoundary1
,
Sint64
pBoundary2
,
SDL_bool
validDomain
,
Sint64
*
outBuffer
,
Uint32
*
outBufferSize
)
{
Sint64
boundary1
=
pBoundary1
,
boundary2
=
pBoundary2
;
if
(
outBuffer
!=
NULL
)
{
SDL_free
(
outBuffer
);
}
if
(
boundary1
>
boundary2
)
{
Sint64
temp
=
boundary1
;
boundary1
=
boundary2
;
boundary2
=
temp
;
}
Sint64
tempBuf
[
8
];
memset
(
tempBuf
,
0
,
8
*
sizeof
(
Sint64
));
Sint64
index
=
0
;
if
(
boundary1
==
boundary2
)
{
tempBuf
[
index
++
]
=
boundary1
;
}
else
if
(
validDomain
)
{
tempBuf
[
index
++
]
=
boundary1
;
if
(
boundary1
<
LLONG_MAX
)
tempBuf
[
index
++
]
=
boundary1
+
1
;
if
(
boundary2
>
LLONG_MIN
)
tempBuf
[
index
++
]
=
boundary2
-
1
;
tempBuf
[
index
++
]
=
boundary2
;
}
else
{
if
(
boundary1
>
minValue
&&
boundary1
>
LLONG_MIN
)
{
tempBuf
[
index
++
]
=
boundary1
-
1
;
}
if
(
boundary2
<
maxValue
&&
boundary2
<
UINT64_MAX
)
{
tempBuf
[
index
++
]
=
boundary2
+
1
;
}
}
if
(
index
==
0
)
{
// There are no valid boundaries
return
NULL
;
}
// Create the return buffer
outBuffer
=
SDL_malloc
(
index
*
sizeof
(
Sint64
));
if
(
outBuffer
==
NULL
)
{
return
NULL
;
}
SDL_memcpy
(
outBuffer
,
tempBuf
,
index
*
sizeof
(
Sint64
));
*
outBufferSize
=
index
;
return
outBuffer
;
}
Sint8
Sint8
RandomSint8BoundaryValue
()
RandomSint8BoundaryValue
(
Sint8
boundary1
,
Sint8
boundary2
,
SDL_bool
validDomain
)
{
Sint64
*
buffer
=
NULL
;
Uint32
size
;
// min & max values for Sint8
const
Sint64
maxValue
=
CHAR_MAX
;
const
Sint64
minValue
=
CHAR_MIN
;
buffer
=
GenerateSignedBoundaryValues
(
minValue
,
maxValue
,
(
Sint64
)
boundary1
,
(
Sint64
)
boundary2
,
validDomain
,
buffer
,
&
size
);
if
(
buffer
==
NULL
)
{
return
CHAR_MIN
;
}
Uint32
index
=
RandomInteger
()
%
size
;
Sint8
retVal
=
(
Sint8
)
buffer
[
index
];
SDL_free
(
buffer
);
return
retVal
;
}
Sint16
RandomSint16BoundaryValue
(
Sint16
boundary1
,
Sint16
boundary2
,
SDL_bool
validDomain
)
{
{
int
value
=
0
;
//GenerateBoundaryValueForSize(8);
Sint64
*
buffer
=
NULL
;
Uint32
size
;
// min & max values for Sint16
const
Sint64
maxValue
=
SHRT_MAX
;
const
Sint64
minValue
=
SHRT_MIN
;
buffer
=
GenerateSignedBoundaryValues
(
minValue
,
maxValue
,
(
Sint64
)
boundary1
,
(
Sint64
)
boundary2
,
validDomain
,
buffer
,
&
size
);
if
(
buffer
==
NULL
)
{
return
SHRT_MIN
;
}
Uint32
index
=
RandomInteger
()
%
size
;
Sint16
retVal
=
(
Sint16
)
buffer
[
index
];
SDL_free
(
buffer
);
return
(
RandomPositiveInteger
()
%
2
==
0
?
value
:
-
value
);
return
retVal
;
}
Sint32
RandomSint32BoundaryValue
(
Sint32
boundary1
,
Sint32
boundary2
,
SDL_bool
validDomain
)
{
Sint64
*
buffer
=
NULL
;
Uint32
size
;
// min & max values for Sint32
const
Sint64
maxValue
=
INT_MAX
;
const
Sint64
minValue
=
INT_MIN
;
buffer
=
GenerateSignedBoundaryValues
(
minValue
,
maxValue
,
(
Sint64
)
boundary1
,
(
Sint64
)
boundary2
,
validDomain
,
buffer
,
&
size
);
if
(
buffer
==
NULL
)
{
return
INT_MIN
;
}
Uint32
index
=
RandomInteger
()
%
size
;
Sint32
retVal
=
(
Sint32
)
buffer
[
index
];
SDL_free
(
buffer
);
return
retVal
;
}
Sint64
RandomSint64BoundaryValue
(
Sint64
boundary1
,
Sint64
boundary2
,
SDL_bool
validDomain
)
{
Sint64
*
buffer
=
NULL
;
Uint32
size
;
// min & max values for Sint64
const
Sint64
maxValue
=
LLONG_MAX
;
const
Sint64
minValue
=
LLONG_MIN
;
buffer
=
GenerateSignedBoundaryValues
(
minValue
,
maxValue
,
(
Sint64
)
boundary1
,
(
Sint64
)
boundary2
,
validDomain
,
buffer
,
&
size
);
if
(
buffer
==
NULL
)
{
return
LLONG_MIN
;
}
Uint32
index
=
RandomInteger
()
%
size
;
Sint64
retVal
=
(
Sint64
)
buffer
[
index
];
SDL_free
(
buffer
);
return
retVal
;
}
}
char
*
char
*
...
...
test/test-automation/src/libSDLtest/fuzzer/fuzzer.h
View file @
dc97e62c
...
@@ -142,10 +142,27 @@ Uint64 RandomUint64BoundaryValue(Uint64 boundary1, Uint64 boundary2, SDL_bool va
...
@@ -142,10 +142,27 @@ Uint64 RandomUint64BoundaryValue(Uint64 boundary1, Uint64 boundary2, SDL_bool va
/*!
/*!
* Returns random Sint8 boundary value.
* Returns random Sint8 boundary value.
*
* Note: not implemented.
*/
*/
Sint8
RandomSint8BoundaryValue
();
Sint8
RandomSint8BoundaryValue
(
Sint8
boundary1
,
Sint8
boundary2
,
SDL_bool
validDomain
);
/*!
* Returns random Sint8 boundary value.
*/
Sint16
RandomSint16BoundaryValue
(
Sint16
boundary1
,
Sint16
boundary2
,
SDL_bool
validDomain
);
/*!
* Returns random Sint8 boundary value.
*/
Sint32
RandomSint32BoundaryValue
(
Sint32
boundary1
,
Sint32
boundary2
,
SDL_bool
validDomain
);
/*!
* Returns random Sint8 boundary value.
*/
Sint64
RandomSint64BoundaryValue
(
Sint64
boundary1
,
Sint64
boundary2
,
SDL_bool
validDomain
);
/*!
/*!
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment