Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
Fuzz Class Reference

#include <Fuzz.h>

Public Member Functions

 Fuzz (const uint8_t *data, size_t size)
 
 Fuzz ()=delete
 
 Fuzz (Fuzz &)=delete
 
Fuzzoperator= (Fuzz &)=delete
 
size_t size () const
 
bool exhausted () const
 
void deplete ()
 
size_t remainingSize () const
 
const uint8_t * remainingData () const
 
template<typename T >
void next (T *t)
 
template<typename Arg , typename... Args>
void next (Arg *first, Args... rest)
 
template<typename T , typename Min , typename Max >
void nextRange (T *, Min, Max)
 
template<typename T >
void nextEnum (T *ptr, T max)
 
template<typename T >
void nextN (T *ptr, int n)
 
void signalBug ()
 
void next (bool *b)
 
void next (SkRegion *region)
 
bool nextBool ()
 
void nextRange (float *f, float min, float max)
 

Friends

void fuzz__MakeEncoderCorpus (Fuzz *)
 

Detailed Description

Definition at line 24 of file Fuzz.h.

Constructor & Destructor Documentation

◆ Fuzz() [1/3]

Fuzz::Fuzz ( const uint8_t *  data,
size_t  size 
)
inlineexplicit

Definition at line 26 of file Fuzz.h.

26: fData(data), fSize(size), fNextByte(0) {}
size_t size() const
Definition Fuzz.h:34

◆ Fuzz() [2/3]

Fuzz::Fuzz ( )
delete

◆ Fuzz() [3/3]

Fuzz::Fuzz ( Fuzz )
delete

Member Function Documentation

◆ deplete()

void Fuzz::deplete ( )
inline

Definition at line 43 of file Fuzz.h.

43 {
44 fNextByte = fSize;
45 }

◆ exhausted()

bool Fuzz::exhausted ( ) const
inline

Definition at line 39 of file Fuzz.h.

39 {
40 return fSize == fNextByte;
41 }

◆ next() [1/4]

template<typename Arg , typename... Args>
void Fuzz::next ( Arg *  first,
Args...  rest 
)
inline

Definition at line 113 of file Fuzz.h.

113 {
114 this->next(first);
115 this->next(rest...);
116}
void next(T *t)
Definition Fuzz.h:64

◆ next() [2/4]

void Fuzz::next ( bool *  b)

Definition at line 13 of file Fuzz.cpp.

13 {
14 uint8_t n;
15 this->next(&n);
16 *b = (n & 1) == 1;
17}
static bool b

◆ next() [3/4]

void Fuzz::next ( SkRegion region)

Definition at line 30 of file Fuzz.cpp.

30 {
31 // See FuzzCommon.h
32 FuzzNiceRegion(this, region, 10);
33}
void FuzzNiceRegion(Fuzz *fuzz, SkRegion *region, int maxN)

◆ next() [4/4]

template<typename T >
void Fuzz::next ( T t)
inline

Definition at line 64 of file Fuzz.h.

64{ this->nextBytes(t, sizeof(T)); }
#define T

◆ nextBool()

bool Fuzz::nextBool ( )
inline

Definition at line 92 of file Fuzz.h.

92 {
93 bool b;
94 this->next(&b);
95 return b;
96 }

◆ nextEnum()

template<typename T >
void Fuzz::nextEnum ( T ptr,
T  max 
)
inline

Definition at line 131 of file Fuzz.h.

131 {
132 // This works around the fact that UBSAN will assert if we put an invalid
133 // value into an enum. We might see issues with enums being represented
134 // on Windows differently than Linux, but that's not a thing we can fix here.
135 using U = typename std::underlying_type<T>::type;
136 U v;
137 this->next(&v);
138 if (v < (U)0) { *value = (T)0; return;}
139 if (v > (U)max) { *value = (T)max; return;}
140 *value = (T)v;
141}
uint8_t value
static float max(float r, float g, float b)
Definition hsl.cpp:49

◆ nextN()

template<typename T >
void Fuzz::nextN ( T ptr,
int  n 
)
inline

Definition at line 144 of file Fuzz.h.

144 {
145 for (int i = 0; i < n; i++) {
146 this->next(ptr+i);
147 }
148}

◆ nextRange() [1/2]

void Fuzz::nextRange ( float *  f,
float  min,
float  max 
)

Definition at line 35 of file Fuzz.cpp.

35 {
36 this->next(f);
37 if (!std::isnormal(*f) && *f != 0.0f) {
38 // Don't deal with infinity or other strange floats.
39 *f = max;
40 }
41 *f = min + std::fmod(std::abs(*f), (max - min + 1));
42}
static float min(float r, float g, float b)
Definition hsl.cpp:48

◆ nextRange() [2/2]

template<typename T , typename Min , typename Max >
void Fuzz::nextRange ( T value,
Min  min,
Max  max 
)
inline

Definition at line 119 of file Fuzz.h.

119 {
120 // UBSAN worries if we make an enum with out of range values, even temporarily.
121 using Raw = typename sk_strip_enum<T>::type;
122 Raw raw;
123 this->next(&raw);
124
125 if (raw < (Raw)min) { raw = (Raw)min; }
126 if (raw > (Raw)max) { raw = (Raw)max; }
127 *value = (T)raw;
128}

◆ operator=()

Fuzz & Fuzz::operator= ( Fuzz )
delete

◆ remainingData()

const uint8_t * Fuzz::remainingData ( ) const
inline

Definition at line 51 of file Fuzz.h.

51 {
52 return fData + fNextByte;
53 }

◆ remainingSize()

size_t Fuzz::remainingSize ( ) const
inline

Definition at line 47 of file Fuzz.h.

47 {
48 return fSize - fNextByte;
49 }

◆ signalBug()

void Fuzz::signalBug ( )
inline

Definition at line 82 of file Fuzz.h.

82 {
83 // Tell the fuzzer that these inputs found a bug.
84 SkDebugf("Signal bug\n");
85 raise(SIGSEGV);
86 }
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1

◆ size()

size_t Fuzz::size ( ) const
inline

Definition at line 34 of file Fuzz.h.

34 {
35 return fSize;
36 }

Friends And Related Symbol Documentation

◆ fuzz__MakeEncoderCorpus

void fuzz__MakeEncoderCorpus ( Fuzz )
friend

The documentation for this class was generated from the following files: