mirror of
https://github.com/nlohmann/json.git
synced 2026-10-11 19:35:16 +00:00
Check the CSV file and the round count in the json_view benchmarks
fopen() of the CSV output was not checked, so an unwritable directory made fprintf() write to a null FILE*; the round count is parsed with strtol and clamped instead of atoi. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -497,7 +497,8 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
const std::string T = std::string(argv[1]) + "/";
|
||||
const int rounds = argc > 2 ? std::atoi(argv[2]) : 20;
|
||||
// (clamped to 1 to a million)
|
||||
const int rounds = argc > 2 ? static_cast<int>((std::min)((std::max)(std::strtol(argv[2], nullptr, 10), 1L), 1000000L)) : 20;
|
||||
const std::string only = argc > 3 ? argv[3] : "";
|
||||
struct doc
|
||||
{
|
||||
@@ -526,6 +527,11 @@ int main(int argc, char** argv)
|
||||
};
|
||||
|
||||
std::FILE* csv = std::fopen("bench_edit.csv", "w");
|
||||
if (csv == nullptr)
|
||||
{
|
||||
std::perror("bench_edit.csv");
|
||||
return 1;
|
||||
}
|
||||
std::fprintf(csv, "doc,bytes,workload,engine,ns\n");
|
||||
for (const auto& dc : docs)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user