ManaPlus
fuzzer.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2013-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "utils/fuzzer.h"
23 
24 #ifdef USE_FUZZER
25 
26 #include "client.h"
27 #include "logger.h"
28 #include "settings.h"
29 
30 #include "utils/stringutils.h"
31 
32 #include "debug.h"
33 
34 namespace
35 {
36  Logger *fuzz = nullptr;
37  int fuzzRand = 50;
38 } // namespace
39 
40 void Fuzzer::init()
41 {
42  fuzz = new Logger;
43  fuzz->setLogFile(pathJoin(settings.localDataDir, "fuzzer.log"));
44  unsigned int sr = time(nullptr);
45 
46  fuzz->log("Srand: %u", sr);
47  srand(sr);
48 }
49 
50 bool Fuzzer::conditionTerminate(const char *const name)
51 {
52  if ((rand() % 100) <= fuzzRand)
53  {
54  fuzz->log("deleted: %s", name);
55  return true;
56  }
57  fuzz->log("passed: %s", name);
58  return false;
59 }
60 
61 #endif // USE_FUZZER
Definition: logger.h:69
void setLogFile(const std::string &logFilename)
Definition: logger.cpp:120
std::string localDataDir
Definition: settings.h:112
void init()
Definition: playerinfo.cpp:434
Settings settings
Definition: settings.cpp:32
std::string pathJoin(std::string str1, const std::string &str2)