# Global Metrics

path: .metrics.cyclomatic.average
old: 1.0
new: 3.736842105263158
path: .metrics.cyclomatic.sum
old: 4.0
new: 71.0
path: .metrics.nexits.sum
old: 0.0
new: 19.0
path: .metrics.nexits.average
old: null
new: 1.1176470588235294
path: .metrics.loc.sloc
old: 76.0
new: 236.0
path: .metrics.loc.cloc
old: 2.0
new: 23.0
path: .metrics.loc.lloc
old: 1.0
new: 116.0
path: .metrics.loc.ploc
old: 59.0
new: 198.0
path: .metrics.halstead.estimated_program_length
old: 534.2835726039698
new: 993.3620423942308
path: .metrics.halstead.N1
old: 152.0
new: 798.0
path: .metrics.halstead.vocabulary
old: 89.0
new: 154.0
path: .metrics.halstead.bugs
old: 0.19891664608201956
new: 3.0260952323190855
path: .metrics.halstead.N2
old: 138.0
new: 529.0
path: .metrics.halstead.difficulty
old: 7.7625
new: 89.7
path: .metrics.halstead.level
old: 0.1288244766505636
new: 0.011148272017837234
path: .metrics.halstead.n1
old: 9.0
new: 39.0
path: .metrics.halstead.n2
old: 80.0
new: 115.0
path: .metrics.halstead.time
old: 809.8714122102351
new: 48054.411601852305
path: .metrics.halstead.volume
old: 1877.9626949802553
new: 9643.025739502134
path: .metrics.halstead.length
old: 290.0
new: 1327.0
path: .metrics.halstead.purity_ratio
old: 1.8423571469102409
new: 0.7485772738464437
path: .metrics.halstead.effort
old: 14577.685419784231
new: 864979.4088333414
path: .metrics.mi.mi_sei
old: 24.747584957202353
new: -18.602411453920578
path: .metrics.mi.mi_original
old: 60.72481735157709
new: 18.45117565749041
path: .metrics.mi.mi_visual_studio
old: 35.51158909448952
new: 10.790161203210769
path: .metrics.nom.functions
old: 0.0
new: 17.0
path: .metrics.nom.total
old: 0.0
new: 17.0
path: .metrics.nargs.sum
old: 0.0
new: 28.0
path: .metrics.nargs.average
old: null
new: 1.6470588235294117
path: .metrics.cognitive.sum
old: 0.0
new: 66.0
path: .metrics.cognitive.average
old: null
new: 3.8823529411764706

# Spaces Data

## Minimal test - lines (25, 236)

path: .spaces[0].metrics.nargs.average
old: null
new: 1.6470588235294117
path: .spaces[0].metrics.nargs.sum
old: 0.0
new: 28.0
path: .spaces[0].metrics.nexits.average
old: null
new: 1.1176470588235294
path: .spaces[0].metrics.nexits.sum
old: 0.0
new: 19.0
path: .spaces[0].metrics.nom.functions
old: 0.0
new: 17.0
path: .spaces[0].metrics.nom.total
old: 0.0
new: 17.0
path: .spaces[0].metrics.cyclomatic.sum
old: 1.0
new: 70.0
path: .spaces[0].metrics.cyclomatic.average
old: 1.0
new: 3.888888888888889
path: .spaces[0].metrics.cognitive.average
old: null
new: 3.8823529411764706
path: .spaces[0].metrics.cognitive.sum
old: 0.0
new: 66.0
path: .spaces[0].metrics.mi.mi_original
old: 112.14948064002309
new: 20.45067174084484
path: .spaces[0].metrics.mi.mi_visual_studio
old: 65.58449160235267
new: 11.959457158388794
path: .spaces[0].metrics.mi.mi_sei
old: 86.19846742502578
new: -20.355056454651617
path: .spaces[0].metrics.halstead.bugs
old: 0.01012968884754032
new: 3.0556307094503063
path: .spaces[0].metrics.halstead.N2
old: 10.0
new: 526.0
path: .spaces[0].metrics.halstead.effort
old: 167.5236165705346
new: 877673.8951116492
path: .spaces[0].metrics.halstead.length
old: 22.0
new: 1324.0
path: .spaces[0].metrics.halstead.N1
old: 12.0
new: 798.0
path: .spaces[0].metrics.halstead.n2
old: 10.0
new: 112.0
path: .spaces[0].metrics.halstead.n1
old: 4.0
new: 39.0
path: .spaces[0].metrics.halstead.level
old: 0.5
new: 0.010919372136102177
path: .spaces[0].metrics.halstead.estimated_program_length
old: 41.219280948873624
new: 968.5544378060792
path: .spaces[0].metrics.halstead.time
old: 9.306867587251922
new: 48759.66083953607
path: .spaces[0].metrics.halstead.purity_ratio
old: 1.8736036794942557
new: 0.7315365844456791
path: .spaces[0].metrics.halstead.vocabulary
old: 14.0
new: 151.0
path: .spaces[0].metrics.halstead.difficulty
old: 2.0
new: 91.58035714285714
path: .spaces[0].metrics.halstead.volume
old: 83.76180828526729
new: 9583.647874866405
path: .spaces[0].metrics.loc.blank
old: 0.0
new: 14.0
path: .spaces[0].metrics.loc.sloc
old: 9.0
new: 212.0
path: .spaces[0].metrics.loc.lloc
old: 0.0
new: 116.0
path: .spaces[0].metrics.loc.cloc
old: 0.0
new: 13.0
path: .spaces[0].metrics.loc.ploc
old: 9.0
new: 185.0

### Code

    namespace fuzzer {

    void PrintHexArray(const uint8_t *Data, size_t Size,
                       const char *PrintAfter) {
      for (size_t i = 0; i < Size; i++)
        Printf("0x%x,", (unsigned)Data[i]);
      Printf("%s", PrintAfter);
    }

    void Print(const Unit &v, const char *PrintAfter) {
      PrintHexArray(v.data(), v.size(), PrintAfter);
    }

    void PrintASCIIByte(uint8_t Byte) {
      if (Byte == '\\')
        Printf("\\\\");
      else if (Byte == '"')
        Printf("\\\"");
      else if (Byte >= 32 && Byte < 127)
        Printf("%c", Byte);
      else
        Printf("\\x%02x", Byte);
    }

    void PrintASCII(const uint8_t *Data, size_t Size, const char *PrintAfter) {
      for (size_t i = 0; i < Size; i++)
        PrintASCIIByte(Data[i]);
      Printf("%s", PrintAfter);
    }

    void PrintASCII(const Unit &U, const char *PrintAfter) {
      PrintASCII(U.data(), U.size(), PrintAfter);
    }

    bool ToASCII(uint8_t *Data, size_t Size) {
      bool Changed = false;
      for (size_t i = 0; i < Size; i++) {
        uint8_t &X = Data[i];
        auto NewX = X;
        NewX &= 127;
        if (!isspace(NewX) && !isprint(NewX))
          NewX = ' ';
        Changed |= NewX != X;
        X = NewX;
      }
      return Changed;
    }

    bool IsASCII(const Unit &U) { return IsASCII(U.data(), U.size()); }

    bool IsASCII(const uint8_t *Data, size_t Size) {
      for (size_t i = 0; i < Size; i++)
        if (!(isprint(Data[i]) || isspace(Data[i]))) return false;
      return true;
    }

    bool ParseOneDictionaryEntry(const std::string &Str, Unit *U) {
      U->clear();
      if (Str.empty()) return false;
      size_t L = 0, R = Str.size() - 1;  // We are parsing the range [L,R].
      // Skip spaces from both sides.
      while (L < R && isspace(Str[L])) L++;
      while (R > L && isspace(Str[R])) R--;
      if (R - L < 2) return false;
      // Check the closing "
      if (Str[R] != '"') return false;
      R--;
      // Find the opening "
      while (L < R && Str[L] != '"') L++;
      if (L >= R) return false;
      assert(Str[L] == '\"');
      L++;
      assert(L <= R);
      for (size_t Pos = L; Pos <= R; Pos++) {
        uint8_t V = (uint8_t)Str[Pos];
        if (!isprint(V) && !isspace(V)) return false;
        if (V =='\\') {
          // Handle '\\'
          if (Pos + 1 <= R && (Str[Pos + 1] == '\\' || Str[Pos + 1] == '"')) {
            U->push_back(Str[Pos + 1]);
            Pos++;
            continue;
          }
          // Handle '\xAB'
          if (Pos + 3 <= R && Str[Pos + 1] == 'x'
               && isxdigit(Str[Pos + 2]) && isxdigit(Str[Pos + 3])) {
            char Hex[] = "0xAA";
            Hex[2] = Str[Pos + 2];
            Hex[3] = Str[Pos + 3];
            U->push_back(strtol(Hex, nullptr, 16));
            Pos += 3;
            continue;
          }
          return false;  // Invalid escape.
        } else {
          // Any other character.
          U->push_back(V);
        }
      }
      return true;
    }

    bool ParseDictionaryFile(const std::string &Text, Vector *Units) {
      if (Text.empty()) {
        Printf("ParseDictionaryFile: file does not exist or is empty\n");
        return false;
      }
      std::istringstream ISS(Text);
      Units->clear();
      Unit U;
      int LineNo = 0;
      std::string S;
      while (std::getline(ISS, S, '\n')) {
        LineNo++;
        size_t Pos = 0;
        while (Pos < S.size() && isspace(S[Pos])) Pos++;  // Skip spaces.
        if (Pos == S.size()) continue;  // Empty line.
        if (S[Pos] == '#') continue;  // Comment line.
        if (ParseOneDictionaryEntry(S, &U)) {
          Units->push_back(U);
        } else {
          Printf("ParseDictionaryFile: error in line %d\n\t\t%s\n", LineNo,
                 S.c_str());
          return false;
        }
      }
      return true;
    }

    // Code duplicated (and tested) in llvm/include/llvm/Support/Base64.h
    std::string Base64(const Unit &U) {
      static const char Table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                  "abcdefghijklmnopqrstuvwxyz"
                                  "0123456789+/";
      std::string Buffer;
      Buffer.resize(((U.size() + 2) / 3) * 4);

      size_t i = 0, j = 0;
      for (size_t n = U.size() / 3 * 3; i < n; i += 3, j += 4) {
        uint32_t x = ((unsigned char)U[i] << 16) | ((unsigned char)U[i + 1] << 8) |
                     (unsigned char)U[i + 2];
        Buffer[j + 0] = Table[(x >> 18) & 63];
        Buffer[j + 1] = Table[(x >> 12) & 63];
        Buffer[j + 2] = Table[(x >> 6) & 63];
        Buffer[j + 3] = Table[x & 63];
      }
      if (i + 1 == U.size()) {
        uint32_t x = ((unsigned char)U[i] << 16);
        Buffer[j + 0] = Table[(x >> 18) & 63];
        Buffer[j + 1] = Table[(x >> 12) & 63];
        Buffer[j + 2] = '=';
        Buffer[j + 3] = '=';
      } else if (i + 2 == U.size()) {
        uint32_t x = ((unsigned char)U[i] << 16) | ((unsigned char)U[i + 1] << 8);
        Buffer[j + 0] = Table[(x >> 18) & 63];
        Buffer[j + 1] = Table[(x >> 12) & 63];
        Buffer[j + 2] = Table[(x >> 6) & 63];
        Buffer[j + 3] = '=';
      }
      return Buffer;
    }

    static std::mutex SymbolizeMutex;

    std::string DescribePC(const char *SymbolizedFMT, uintptr_t PC) {
      std::unique_lock l(SymbolizeMutex, std::try_to_lock);
      if (!EF->__sanitizer_symbolize_pc || !l.owns_lock())
        return "";
      char PcDescr[1024] = {};
      EF->__sanitizer_symbolize_pc(reinterpret_cast(PC),
                                   SymbolizedFMT, PcDescr, sizeof(PcDescr));
      PcDescr[sizeof(PcDescr) - 1] = 0;  // Just in case.
      return PcDescr;
    }

    void PrintPC(const char *SymbolizedFMT, const char *FallbackFMT, uintptr_t PC) {
      if (EF->__sanitizer_symbolize_pc)
        Printf("%s", DescribePC(SymbolizedFMT, PC).c_str());
      else
        Printf(FallbackFMT, PC);
    }

    void PrintStackTrace() {
      std::unique_lock l(SymbolizeMutex, std::try_to_lock);
      if (EF->__sanitizer_print_stack_trace && l.owns_lock())
        EF->__sanitizer_print_stack_trace();
    }

    void PrintMemoryProfile() {
      std::unique_lock l(SymbolizeMutex, std::try_to_lock);
      if (EF->__sanitizer_print_memory_profile && l.owns_lock())
        EF->__sanitizer_print_memory_profile(95, 8);
    }

    unsigned NumberOfCpuCores() {
      unsigned N = std::thread::hardware_concurrency();
      if (!N) {
        Printf("WARNING: std::thread::hardware_concurrency not well defined for "
               "your platform. Assuming CPU count of 1.\n");
        N = 1;
      }
      return N;
    }

    size_t SimpleFastHash(const uint8_t *Data, size_t Size) {
      size_t Res = 0;
      for (size_t i = 0; i < Size; i++)
        Res = Res * 11 + Data[i];
      return Res;
    }

    }  // namespace fuzzer