Global Metrics
path: .metrics.cyclomatic.average
old: 1.0
new: 2.0
path: .metrics.cyclomatic.sum
old: 4.0
new: 38.0
path: .metrics.cognitive.average
old: null
new: 1.2105263157894737
path: .metrics.cognitive.sum
old: 0.0
new: 23.0
path: .metrics.halstead.volume
old: 644.1496881499434
new: 5547.431400813863
path: .metrics.halstead.n2
old: 39.0
new: 112.0
path: .metrics.halstead.time
old: 322.0748440749717
new: 12448.700226826348
path: .metrics.halstead.estimated_program_length
old: 254.23640287146188
new: 903.3052001291512
path: .metrics.halstead.level
old: 0.1111111111111111
new: 0.024756852343059237
path: .metrics.halstead.N1
old: 59.0
new: 465.0
path: .metrics.halstead.vocabulary
old: 52.0
new: 141.0
path: .metrics.halstead.length
old: 113.0
new: 777.0
path: .metrics.halstead.purity_ratio
old: 2.2498796714288662
new: 1.162554955121173
path: .metrics.halstead.bugs
old: 0.10757176278405182
new: 1.2297299621018802
path: .metrics.halstead.difficulty
old: 9.0
new: 40.392857142857146
path: .metrics.halstead.effort
old: 5797.34719334949
new: 224076.60408287423
path: .metrics.halstead.N2
old: 54.0
new: 312.0
path: .metrics.halstead.n1
old: 13.0
new: 29.0
path: .metrics.nexits.sum
old: 0.0
new: 9.0
path: .metrics.nexits.average
old: null
new: 0.47368421052631576
path: .metrics.loc.lloc
old: 0.0
new: 56.0
path: .metrics.loc.sloc
old: 52.0
new: 160.0
path: .metrics.loc.ploc
old: 32.0
new: 127.0
path: .metrics.loc.blank
old: 12.0
new: 19.0
path: .metrics.loc.cloc
old: 8.0
new: 14.0
path: .metrics.nom.total
old: 0.0
new: 19.0
path: .metrics.nom.closures
old: 0.0
new: 3.0
path: .metrics.nom.functions
old: 0.0
new: 16.0
path: .metrics.mi.mi_visual_studio
old: 42.360590562341464
new: 20.592113854205113
path: .metrics.mi.mi_original
old: 72.4366098616039
new: 35.21251469069074
path: .metrics.mi.mi_sei
old: 57.75708874508783
new: 1.0885292179978627
path: .metrics.nargs.average
old: null
new: 1.5789473684210529
path: .metrics.nargs.sum
old: 0.0
new: 30.0
Spaces Data
Minimal test - lines (23, 160)
path: .spaces[0].metrics.cognitive.sum
old: 0.0
new: 23.0
path: .spaces[0].metrics.cognitive.average
old: null
new: 1.2105263157894737
path: .spaces[0].metrics.cyclomatic.average
old: 1.0
new: 2.0555555555555554
path: .spaces[0].metrics.cyclomatic.sum
old: 3.0
new: 37.0
path: .spaces[0].metrics.nom.functions
old: 0.0
new: 16.0
path: .spaces[0].metrics.nom.total
old: 0.0
new: 19.0
path: .spaces[0].metrics.nom.closures
old: 0.0
new: 3.0
path: .spaces[0].metrics.loc.cloc
old: 1.0
new: 4.0
path: .spaces[0].metrics.loc.lloc
old: 0.0
new: 56.0
path: .spaces[0].metrics.loc.ploc
old: 26.0
new: 116.0
path: .spaces[0].metrics.loc.sloc
old: 37.0
new: 138.0
path: .spaces[0].metrics.loc.blank
old: 10.0
new: 18.0
path: .spaces[0].metrics.mi.mi_sei
old: 50.484461569300336
new: -4.2050323843554445
path: .spaces[0].metrics.mi.mi_original
old: 78.5216432994041
new: 37.91046802417267
path: .spaces[0].metrics.mi.mi_visual_studio
old: 45.91908964877433
new: 22.169864341621448
path: .spaces[0].metrics.nargs.average
old: null
new: 1.5789473684210529
path: .spaces[0].metrics.nargs.sum
old: 0.0
new: 30.0
path: .spaces[0].metrics.halstead.n2
old: 35.0
new: 107.0
path: .spaces[0].metrics.halstead.time
old: 304.9389525393751
new: 12646.145964071437
path: .spaces[0].metrics.halstead.effort
old: 5488.901145708752
new: 227630.62735328585
path: .spaces[0].metrics.halstead.N2
old: 49.0
new: 307.0
path: .spaces[0].metrics.halstead.N1
old: 59.0
new: 465.0
path: .spaces[0].metrics.halstead.volume
old: 603.1759500778849
new: 5471.5213134452615
path: .spaces[0].metrics.halstead.bugs
old: 0.1037215547643092
new: 1.242698790057779
path: .spaces[0].metrics.halstead.difficulty
old: 9.1
new: 41.60280373831776
path: .spaces[0].metrics.halstead.n1
old: 13.0
new: 29.0
path: .spaces[0].metrics.halstead.level
old: 0.10989010989010987
new: 0.02403684151409637
path: .spaces[0].metrics.halstead.purity_ratio
old: 2.107690943786185
new: 1.1168632336834483
path: .spaces[0].metrics.halstead.estimated_program_length
old: 227.630621928908
new: 862.2184164036223
path: .spaces[0].metrics.halstead.length
old: 108.0
new: 772.0
path: .spaces[0].metrics.halstead.vocabulary
old: 48.0
new: 136.0
path: .spaces[0].metrics.nexits.average
old: null
new: 0.47368421052631576
path: .spaces[0].metrics.nexits.sum
old: 0.0
new: 9.0
Code
namespace fuzzer {
static FILE *OutputFile = stderr;
long GetEpoch(const std::string &Path) {
struct stat St;
if (stat(Path.c_str(), &St))
return 0; // Can't stat, be conservative.
return St.st_mtime;
}
Unit FileToVector(const std::string &Path, size_t MaxSize, bool ExitOnError) {
std::ifstream T(Path, std::ios::binary);
if (ExitOnError && !T) {
Printf("No such directory: %s; exiting\n", Path.c_str());
exit(1);
}
T.seekg(0, T.end);
auto EndPos = T.tellg();
if (EndPos < 0) return {};
size_t FileLen = EndPos;
if (MaxSize)
FileLen = std::min(FileLen, MaxSize);
T.seekg(0, T.beg);
Unit Res(FileLen);
T.read(reinterpret_cast(Res.data()), FileLen);
return Res;
}
std::string FileToString(const std::string &Path) {
std::ifstream T(Path, std::ios::binary);
return std::string((std::istreambuf_iterator(T)),
std::istreambuf_iterator());
}
void CopyFileToErr(const std::string &Path) {
Printf("%s", FileToString(Path).c_str());
}
void WriteToFile(const Unit &U, const std::string &Path) {
WriteToFile(U.data(), U.size(), Path);
}
void WriteToFile(const std::string &Data, const std::string &Path) {
WriteToFile(reinterpret_cast(Data.c_str()), Data.size(),
Path);
}
void WriteToFile(const uint8_t *Data, size_t Size, const std::string &Path) {
// Use raw C interface because this function may be called from a sig handler.
FILE *Out = fopen(Path.c_str(), "wb");
if (!Out) return;
mozilla::Unused << fwrite(Data, sizeof(Data[0]), Size, Out);
fclose(Out);
}
void ReadDirToVectorOfUnits(const char *Path, Vector *V,
long *Epoch, size_t MaxSize, bool ExitOnError) {
long E = Epoch ? *Epoch : 0;
Vector Files;
ListFilesInDirRecursive(Path, Epoch, &Files, /*TopDir*/true);
size_t NumLoaded = 0;
for (size_t i = 0; i < Files.size(); i++) {
auto &X = Files[i];
if (Epoch && GetEpoch(X) < E) continue;
NumLoaded++;
if ((NumLoaded & (NumLoaded - 1)) == 0 && NumLoaded >= 1024)
Printf("Loaded %zd/%zd files from %s\n", NumLoaded, Files.size(), Path);
auto S = FileToVector(X, MaxSize, ExitOnError);
if (!S.empty())
V->push_back(S);
}
}
void GetSizedFilesFromDir(const std::string &Dir, Vector *V) {
Vector Files;
ListFilesInDirRecursive(Dir, 0, &Files, /*TopDir*/true);
for (auto &File : Files)
if (size_t Size = FileSize(File))
V->push_back({File, Size});
}
std::string DirPlusFile(const std::string &DirPath,
const std::string &FileName) {
return DirPath + GetSeparator() + FileName;
}
void DupAndCloseStderr() {
int OutputFd = DuplicateFile(2);
if (OutputFd >= 0) {
FILE *NewOutputFile = OpenFile(OutputFd, "w");
if (NewOutputFile) {
OutputFile = NewOutputFile;
if (EF->__sanitizer_set_report_fd)
EF->__sanitizer_set_report_fd(
reinterpret_cast(GetHandleFromFd(OutputFd)));
DiscardOutput(2);
}
}
}
void CloseStdout() {
DiscardOutput(1);
}
void Printf(const char *Fmt, ...) {
va_list ap;
va_start(ap, Fmt);
vfprintf(OutputFile, Fmt, ap);
va_end(ap);
fflush(OutputFile);
}
void VPrintf(bool Verbose, const char *Fmt, ...) {
if (!Verbose) return;
va_list ap;
va_start(ap, Fmt);
vfprintf(OutputFile, Fmt, ap);
va_end(ap);
fflush(OutputFile);
}
void RmDirRecursive(const std::string &Dir) {
IterateDirRecursive(
Dir, [](const std::string &Path) {},
[](const std::string &Path) { RmDir(Path); },
[](const std::string &Path) { RemoveFile(Path); });
}
std::string TempPath(const char *Prefix, const char *Extension) {
return DirPlusFile(TmpDir(), std::string("libFuzzerTemp.") + Prefix +
std::to_string(GetPid()) + Extension);
}
} // namespace fuzzer
Minimal test - lines (28, 28)
path: .spaces[0].spaces[0].spaces[0].metrics.loc.blank
old: 9.0
new: 0.0
path: .spaces[0].spaces[0].spaces[0].metrics.loc.ploc
old: 22.0
new: 1.0
path: .spaces[0].spaces[0].spaces[0].metrics.loc.sloc
old: 31.0
new: 1.0
path: .spaces[0].spaces[0].spaces[0].metrics.mi.mi_visual_studio
old: 48.042045199612915
new: null
path: .spaces[0].spaces[0].spaces[0].metrics.mi.mi_sei
old: 42.921102689224625
new: null
path: .spaces[0].spaces[0].spaces[0].metrics.mi.mi_original
old: 82.15189729133809
new: null
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.n1
old: 13.0
new: 0.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.N1
old: 56.0
new: 0.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.N2
old: 47.0
new: 1.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.effort
old: 5266.8837057656965
new: 0.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.level
old: 0.10801963993453356
new: null
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.volume
old: 568.9268814738723
new: 0.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.estimated_program_length
old: 214.57072227466315
new: null
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.purity_ratio
old: 2.083210895870516
new: null
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.n2
old: 33.0
new: 1.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.time
old: 292.60465032031647
new: 0.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.difficulty
old: 9.257575757575758
new: 0.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.length
old: 103.0
new: 1.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.vocabulary
old: 46.0
new: 1.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.bugs
old: 0.1009054363298151
new: 0.0
Code
struct stat St;
Minimal test - lines (27, 32)
path: .spaces[0].spaces[0].metrics.nexits.average
old: null
new: 2.0
path: .spaces[0].spaces[0].metrics.nexits.sum
old: 0.0
new: 2.0
path: .spaces[0].spaces[0].metrics.nom.functions
old: 0.0
new: 1.0
path: .spaces[0].spaces[0].metrics.nom.total
old: 0.0
new: 1.0
path: .spaces[0].spaces[0].metrics.cognitive.average
old: null
new: 1.0
path: .spaces[0].spaces[0].metrics.cognitive.sum
old: 0.0
new: 1.0
path: .spaces[0].spaces[0].metrics.nargs.sum
old: 0.0
new: 1.0
path: .spaces[0].spaces[0].metrics.nargs.average
old: null
new: 1.0
path: .spaces[0].spaces[0].metrics.mi.mi_original
old: 79.77743120197324
new: 116.45235116672234
path: .spaces[0].spaces[0].metrics.mi.mi_sei
old: 39.59729209674346
new: 122.16619297505572
path: .spaces[0].spaces[0].metrics.mi.mi_visual_studio
old: 46.65346853916564
new: 68.10079015597798
path: .spaces[0].spaces[0].metrics.loc.sloc
old: 35.0
new: 6.0
path: .spaces[0].spaces[0].metrics.loc.blank
old: 11.0
new: 0.0
path: .spaces[0].spaces[0].metrics.loc.cloc
old: 0.0
new: 1.0
path: .spaces[0].spaces[0].metrics.loc.ploc
old: 24.0
new: 6.0
path: .spaces[0].spaces[0].metrics.loc.lloc
old: 0.0
new: 3.0
path: .spaces[0].spaces[0].metrics.halstead.bugs
old: 0.1026363152966502
new: 0.02872868874940668
path: .spaces[0].spaces[0].metrics.halstead.estimated_program_length
old: 221.07945293834572
new: 52.529325012980806
path: .spaces[0].spaces[0].metrics.halstead.time
old: 300.1656250043837
new: 44.451158398597435
path: .spaces[0].spaces[0].metrics.halstead.vocabulary
old: 47.0
new: 17.0
path: .spaces[0].spaces[0].metrics.halstead.level
old: 0.10897435897435898
new: 0.14814814814814814
path: .spaces[0].spaces[0].metrics.halstead.purity_ratio
old: 2.085655216399488
new: 1.8113560349303728
path: .spaces[0].spaces[0].metrics.halstead.n2
old: 34.0
new: 8.0
path: .spaces[0].spaces[0].metrics.halstead.effort
old: 5402.981250078907
new: 800.1208511747539
path: .spaces[0].spaces[0].metrics.halstead.volume
old: 588.7864182778296
new: 118.53642239625984
path: .spaces[0].spaces[0].metrics.halstead.N2
old: 48.0
new: 12.0
path: .spaces[0].spaces[0].metrics.halstead.N1
old: 58.0
new: 17.0
path: .spaces[0].spaces[0].metrics.halstead.n1
old: 13.0
new: 9.0
path: .spaces[0].spaces[0].metrics.halstead.difficulty
old: 9.176470588235292
new: 6.75
path: .spaces[0].spaces[0].metrics.halstead.length
old: 106.0
new: 29.0
path: .spaces[0].spaces[0].metrics.cyclomatic.average
old: 1.0
new: 1.5
path: .spaces[0].spaces[0].metrics.cyclomatic.sum
old: 2.0
new: 3.0
Code
long GetEpoch(const std::string &Path) {
struct stat St;
if (stat(Path.c_str(), &St))
return 0; // Can't stat, be conservative.
return St.st_mtime;
}