Global Metrics

path: .metrics.cyclomatic.sum
old: 28.0
new: 34.0

path: .metrics.cyclomatic.average
old: 5.6
new: 1.096774193548387

path: .metrics.halstead.N1
old: 483.0
new: 283.0

path: .metrics.halstead.purity_ratio
old: 1.4836580651889084
new: 1.1137179691355923

path: .metrics.halstead.bugs
old: 1.1731009813641362
new: 0.6884298723174325

path: .metrics.halstead.difficulty
old: 32.90909090909091
new: 31.636363636363637

path: .metrics.halstead.level
old: 0.030386740331491715
new: 0.031609195402298854

path: .metrics.halstead.vocabulary
old: 182.0
new: 90.0

path: .metrics.halstead.time
old: 11598.784356012016
new: 5214.335096100435

path: .metrics.halstead.volume
old: 6344.086470967898
new: 2966.7768650226612

path: .metrics.halstead.effort
old: 208778.11840821628
new: 93858.03172980784

path: .metrics.halstead.n1
old: 28.0
new: 24.0

path: .metrics.halstead.n2
old: 154.0
new: 66.0

path: .metrics.halstead.estimated_program_length
old: 1253.6910650846276
new: 508.9691118949657

path: .metrics.halstead.length
old: 845.0
new: 457.0

path: .metrics.halstead.N2
old: 362.0
new: 174.0

path: .metrics.cognitive.sum
old: 35.0
new: 3.0

path: .metrics.cognitive.average
old: 8.75
new: 0.1111111111111111

path: .metrics.loc.ploc
old: 201.0
new: 85.0

path: .metrics.loc.cloc
old: 16.0
new: 17.0

path: .metrics.loc.sloc
old: 228.0
new: 118.0

path: .metrics.loc.lloc
old: 79.0
new: 31.0

path: .metrics.loc.blank
old: 11.0
new: 16.0

path: .metrics.nom.closures
old: 0.0
new: 1.0

path: .metrics.nom.functions
old: 4.0
new: 26.0

path: .metrics.nom.total
old: 4.0
new: 27.0

path: .metrics.nexits.sum
old: 4.0
new: 16.0

path: .metrics.nexits.average
old: 1.0
new: 0.5925925925925926

path: .metrics.mi.mi_original
old: 31.07715316434222
new: 44.31970574190363

path: .metrics.mi.mi_visual_studio
old: 18.173773780317088
new: 25.917956574212653

path: .metrics.mi.mi_sei
old: -8.066630959546643
new: 19.436406357269632

path: .metrics.nargs.sum
old: 6.0
new: 11.0

path: .metrics.nargs.average
old: 1.5
new: 0.4074074074074074

Spaces Data

Minimal test - lines (20, 116)

path: .spaces[0].metrics.nom.closures
old: 0.0
new: 1.0

path: .spaces[0].metrics.nom.functions
old: 1.0
new: 26.0

path: .spaces[0].metrics.nom.total
old: 1.0
new: 27.0

path: .spaces[0].metrics.nexits.sum
old: 0.0
new: 16.0

path: .spaces[0].metrics.nexits.average
old: 0.0
new: 0.5925925925925926

path: .spaces[0].metrics.cyclomatic.sum
old: 1.0
new: 33.0

path: .spaces[0].metrics.cyclomatic.average
old: 1.0
new: 1.1

path: .spaces[0].metrics.loc.ploc
old: 7.0
new: 77.0

path: .spaces[0].metrics.loc.blank
old: 0.0
new: 14.0

path: .spaces[0].metrics.loc.sloc
old: 7.0
new: 97.0

path: .spaces[0].metrics.loc.cloc
old: 0.0
new: 6.0

path: .spaces[0].metrics.loc.lloc
old: 4.0
new: 31.0

path: .spaces[0].metrics.mi.mi_visual_studio
old: 67.30832023207599
new: 27.973385274321583

path: .spaces[0].metrics.mi.mi_original
old: 115.09722759684992
new: 47.83448881908991

path: .spaces[0].metrics.mi.mi_sei
old: 90.45116734143544
new: 15.46149191733184

path: .spaces[0].metrics.halstead.vocabulary
old: 12.0
new: 86.0

path: .spaces[0].metrics.halstead.difficulty
old: 4.642857142857143
new: 32.70967741935484

path: .spaces[0].metrics.halstead.N2
old: 13.0
new: 169.0

path: .spaces[0].metrics.halstead.effort
old: 482.68959384709854
new: 95010.87330622911

path: .spaces[0].metrics.halstead.bugs
old: 0.020511182682883208
new: 0.6940556361041721

path: .spaces[0].metrics.halstead.N1
old: 16.0
new: 283.0

path: .spaces[0].metrics.halstead.n2
old: 7.0
new: 62.0

path: .spaces[0].metrics.halstead.length
old: 29.0
new: 452.0

path: .spaces[0].metrics.halstead.estimated_program_length
old: 31.26112492884004
new: 479.199271261294

path: .spaces[0].metrics.halstead.purity_ratio
old: 1.0779698251324152
new: 1.060175378896668

path: .spaces[0].metrics.halstead.n1
old: 5.0
new: 24.0

path: .spaces[0].metrics.halstead.volume
old: 103.96391252091352
new: 2904.671669125348

path: .spaces[0].metrics.halstead.level
old: 0.21538461538461537
new: 0.03057199211045365

path: .spaces[0].metrics.halstead.time
old: 26.816088547061028
new: 5278.3818503460625

path: .spaces[0].metrics.cognitive.sum
old: 0.0
new: 3.0

path: .spaces[0].metrics.cognitive.average
old: 0.0
new: 0.1111111111111111

path: .spaces[0].metrics.nargs.average
old: 1.0
new: 0.4074074074074074

path: .spaces[0].metrics.nargs.sum
old: 1.0
new: 11.0

Code

namespace fuzzer {
// A simple POD sized array of bytes.
template  class FixedWord {
public:
  static const size_t kMaxSize = kMaxSizeT;
  FixedWord() {}
  FixedWord(const uint8_t *B, uint8_t S) { Set(B, S); }

  void Set(const uint8_t *B, uint8_t S) {
    assert(S <= kMaxSize);
    memcpy(Data, B, S);
    Size = S;
  }

  bool operator==(const FixedWord &w) const {
    return Size == w.Size && 0 == memcmp(Data, w.Data, Size);
  }

  static size_t GetMaxSize() { return kMaxSize; }
  const uint8_t *data() const { return Data; }
  uint8_t size() const { return Size; }

private:
  uint8_t Size = 0;
  uint8_t Data[kMaxSize];
};

typedef FixedWord<64> Word;

class DictionaryEntry {
 public:
  DictionaryEntry() {}
  DictionaryEntry(Word W) : W(W) {}
  DictionaryEntry(Word W, size_t PositionHint) : W(W), PositionHint(PositionHint) {}
  const Word &GetW() const { return W; }

  bool HasPositionHint() const { return PositionHint != std::numeric_limits::max(); }
  size_t GetPositionHint() const {
    assert(HasPositionHint());
    return PositionHint;
  }
  void IncUseCount() { UseCount++; }
  void IncSuccessCount() { SuccessCount++; }
  size_t GetUseCount() const { return UseCount; }
  size_t GetSuccessCount() const {return SuccessCount; }

  void Print(const char *PrintAfter = "\n") {
    PrintASCII(W.data(), W.size());
    if (HasPositionHint())
      Printf("@%zd", GetPositionHint());
    Printf("%s", PrintAfter);
  }

private:
  Word W;
  size_t PositionHint = std::numeric_limits::max();
  size_t UseCount = 0;
  size_t SuccessCount = 0;
};

class Dictionary {
 public:
  static const size_t kMaxDictSize = 1 << 14;

  bool ContainsWord(const Word &W) const {
    return std::any_of(begin(), end(), [&](const DictionaryEntry &DE) {
      return DE.GetW() == W;
    });
  }
  const DictionaryEntry *begin() const { return &DE[0]; }
  const DictionaryEntry *end() const { return begin() + Size; }
  DictionaryEntry & operator[] (size_t Idx) {
    assert(Idx < Size);
    return DE[Idx];
  }
  void push_back(DictionaryEntry DE) {
    if (Size < kMaxDictSize)
      this->DE[Size++] = DE;
  }
  void clear() { Size = 0; }
  bool empty() const { return Size == 0; }
  size_t size() const { return Size; }

private:
  DictionaryEntry DE[kMaxDictSize];
  size_t Size = 0;
};

// Parses one dictionary entry.
// If successful, write the enty to Unit and returns true,
// otherwise returns false.
bool ParseOneDictionaryEntry(const std::string &Str, Unit *U);
// Parses the dictionary file, fills Units, returns true iff all lines
// were parsed successfully.
bool ParseDictionaryFile(const std::string &Text, Vector *Units);

}  // namespace fuzzer