55
66#define ZEROERR_VERSION_MAJOR 0
77#define ZEROERR_VERSION_MINOR 2
8- #define ZEROERR_VERSION_PATCH 0
8+ #define ZEROERR_VERSION_PATCH 1
99#define ZEROERR_VERSION \
1010 (ZEROERR_VERSION_MAJOR * 10000 + ZEROERR_VERSION_MINOR * 100 + ZEROERR_VERSION_PATCH)
11- #define ZEROERR_VERSION_STR " 0.2.0"
11+
12+ #define ZEROERR_STR (x ) #x
13+
14+ #define ZEROERR_VERSION_STR_BUILDER (a, b, c ) ZEROERR_STR(a) " ." ZEROERR_STR(b) " ." ZEROERR_STR(c)
15+ #define ZEROERR_VERSION_STR \
16+ ZEROERR_VERSION_STR_BUILDER (ZEROERR_VERSION_MAJOR, ZEROERR_VERSION_MINOR, ZEROERR_VERSION_PATCH)
1217
1318// If you just wish to use the color without dynamic
1419// enable or disable it, you can uncomment the following line
@@ -686,11 +691,11 @@ __attribute__((always_inline)) __inline__ static bool isDebuggerActive() { retur
686691#pragma once
687692
688693
689- #include < type_traits>
690694#include < ostream>
691695#include < sstream>
692696#include < string>
693697#include < tuple> // this should be removed
698+ #include < type_traits>
694699
695700ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
696701
@@ -908,7 +913,7 @@ void visit2_at(std::tuple<Ts...>& tup1, std::tuple<T2s...> const& tup2, size_t i
908913
909914} // namespace detail
910915
911- } // namespace zeroerr
916+ } // namespace zeroerr
912917
913918
914919ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
@@ -2052,9 +2057,7 @@ class ElementOf : public Domain<T, uint64_t> {
20522057
20532058 CorpusType FromValue (const ValueType& v) const override {
20542059 for (size_t i = 0 ; i < elements.size (); i++) {
2055- if (elements[i] == v) {
2056- return i;
2057- }
2060+ if (elements[i] == v) return i;
20582061 }
20592062 return 0 ;
20602063 }
@@ -2410,6 +2413,7 @@ class Arbitrary<
24102413 T, typename std::enable_if<detail::is_specialization<T, std::basic_string>::value>::type>
24112414 : public Domain<T, std::vector<typename T::value_type>> {
24122415 Arbitrary<std::vector<typename T::value_type>> impl;
2416+
24132417public:
24142418 using ValueType = T;
24152419 using CorpusType = std::vector<typename T::value_type>;
@@ -2419,9 +2423,7 @@ class Arbitrary<
24192423 return CorpusType (v.begin (), v.end ());
24202424 }
24212425
2422- CorpusType GetRandomCorpus (Rng& rng) const override {
2423- return impl.GetRandomCorpus (rng);
2424- }
2426+ CorpusType GetRandomCorpus (Rng& rng) const override { return impl.GetRandomCorpus (rng); }
24252427
24262428 void Mutate (Rng& rng, CorpusType& v, bool only_shrink) const override {
24272429 impl.Mutate (rng, v, only_shrink);
@@ -2452,11 +2454,13 @@ class Arbitrary<
24522454
24532455template <typename T, typename U>
24542456class Arbitrary <std::pair<T, U>>
2455- : public AggregateOf<std::pair<typename std::remove_const<T>::type, typename std::remove_const<U>::type>> {};
2457+ : public AggregateOf<
2458+ std::pair<typename std::remove_const<T>::type, typename std::remove_const<U>::type>> {};
24562459
24572460
24582461template <typename ... T>
2459- class Arbitrary <std::tuple<T...>> : public AggregateOf<std::tuple<typename std::remove_const<T>::type...>> {};
2462+ class Arbitrary <std::tuple<T...>>
2463+ : public AggregateOf<std::tuple<typename std::remove_const<T>::type...>> {};
24602464
24612465template <typename T>
24622466class Arbitrary <const T> : public Arbitrary<T> {};
@@ -3926,24 +3930,32 @@ extern void RunFuzzTest(IFuzzTest& fuzz_test, int seed = 0, int runs = 1000, int
39263930
39273931template <typename TargetFunction, typename FuncType, typename Domain, typename Base>
39283932struct FuzzTestWithDomain : public Base {
3929- FuzzTestWithDomain (const Base& ft, const Domain& domain) : Base(ft), domain (domain) {}
3933+ FuzzTestWithDomain (const Base& ft, const Domain& domain) : Base(ft), m_domain (domain) {}
39303934
39313935 virtual void Run (int _count = 1000 , int _seed = 0 ) override {
39323936 Base::count = 1 ;
39333937 Base::max_count = _count;
3934- rng = new Rng (_seed);
3938+ m_rng = new Rng (_seed);
39353939 RunFuzzTest (*this , _seed, _count, 500 , 1200 , 1 );
3936- delete rng;
3937- rng = nullptr ;
3940+ delete m_rng;
3941+ m_rng = nullptr ;
3942+ }
3943+
3944+ typename Domain::CorpusType GetRandomCorpus () {
3945+ Rng& rng = *this ->m_rng ;
3946+ if (Base::seeds.size () > 0 && rng.bounded (2 ) == 0 ) {
3947+ return m_domain.FromValue (Base::seeds[rng () % Base::seeds.size ()]);
3948+ }
3949+ return m_domain.GetRandomCorpus (rng);
39383950 }
39393951
39403952 typename Domain::CorpusType TryParse (const std::string& input) {
39413953 try {
39423954 IRObject obj = IRObject::FromString (input);
3943- if (obj.type == IRObject::Type::Undefined) return domain. GetRandomCorpus (*rng );
3944- return domain .ParseCorpus (obj);
3955+ if (obj.type == IRObject::Type::Undefined) return GetRandomCorpus ();
3956+ return m_domain .ParseCorpus (obj);
39453957 } catch (...) {
3946- return domain. GetRandomCorpus (*rng );
3958+ return GetRandomCorpus ();
39473959 }
39483960 }
39493961
@@ -3956,22 +3968,22 @@ struct FuzzTestWithDomain : public Base {
39563968 Base::count++;
39573969 std::string input = std::string ((const char *)data, size);
39583970 typename Domain::CorpusType corpus = TryParse (input);
3959- typename Domain::ValueType value = domain .GetValue (corpus);
3971+ typename Domain::ValueType value = m_domain .GetValue (corpus);
39603972 apply (value, detail::gen_seq<std::tuple_size<typename Domain::ValueType>::value>{});
39613973 }
39623974
39633975 virtual std::string MutateData (const uint8_t * data, size_t size, size_t max_size,
39643976 unsigned int seed) override {
3965- Rng mrng (seed);
3977+ Rng rng (seed);
39663978 std::string input = std::string ((const char *)data, size);
39673979 typename Domain::CorpusType corpus = TryParse (input);
3968- domain .Mutate (mrng , corpus, false );
3969- IRObject mutated_obj = domain .SerializeCorpus (corpus);
3980+ m_domain .Mutate (rng , corpus, false );
3981+ IRObject mutated_obj = m_domain .SerializeCorpus (corpus);
39703982 return IRObject::ToString (mutated_obj);
39713983 }
39723984
3973- Domain domain ;
3974- Rng* rng ;
3985+ Domain m_domain ;
3986+ Rng* m_rng ;
39753987};
39763988
39773989
@@ -5528,10 +5540,10 @@ class XmlReporter : public IReporter {
55285540
55295541 struct TestCaseData {
55305542 struct TestCase {
5531- std::string filename, name;
5532- unsigned line;
5533- double time;
5534- TestContext context;
5543+ std::string filename, name;
5544+ unsigned line;
5545+ double time;
5546+ TestContext context;
55355547 };
55365548
55375549 std::vector<TestCase> testcases;
0 commit comments