1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 12:41:29 +00:00

Const-ify a few things, add a copy constructor

This commit is contained in:
dmiller
2022-12-02 21:57:29 +00:00
parent 7dcca32ff1
commit d113e08de1
2 changed files with 7 additions and 6 deletions

View File

@@ -642,7 +642,7 @@ const char *FingerTest::getAValName(u8 index) const {
return def->Attrs.at(index).name; return def->Attrs.at(index).name;
} }
const char *FingerTest::getAVal(const char *attr) { const char *FingerTest::getAVal(const char *attr) const {
if (!results) if (!results)
return NULL; return NULL;

View File

@@ -153,8 +153,8 @@ class FingerPrintDef {
bool parseTestStr(const char *str, const char *end); bool parseTestStr(const char *str, const char *end);
FingerTestDef &getTestDef(TestID id) { return TestDefs[ID2INT(id)]; } FingerTestDef &getTestDef(TestID id) { return TestDefs[ID2INT(id)]; }
const FingerTestDef &getTestDef(TestID id) const { return TestDefs[ID2INT(id)]; } const FingerTestDef &getTestDef(TestID id) const { return TestDefs[ID2INT(id)]; }
int getTestIndex(FPstr testname) { return ID2INT(TestIdx.at(testname)); } int getTestIndex(const FPstr testname) const { return ID2INT(TestIdx.at(testname)); }
TestID str2TestID(FPstr testname) { return TestIdx.at(testname); } TestID str2TestID(const FPstr testname) const { return TestIdx.at(testname); }
private: private:
std::map<FPstr, TestID> TestIdx; std::map<FPstr, TestID> TestIdx;
@@ -189,23 +189,24 @@ struct FingerTest {
const FingerTestDef *def; const FingerTestDef *def;
std::vector<const char *> *results; std::vector<const char *> *results;
FingerTest() : id(FingerPrintDef::INVALID), def(NULL), results(NULL) {} FingerTest() : id(FingerPrintDef::INVALID), def(NULL), results(NULL) {}
FingerTest(const FPstr &testname, FingerPrintDef &Defs) { FingerTest(const FPstr &testname, const FingerPrintDef &Defs) {
id = Defs.str2TestID(testname); id = Defs.str2TestID(testname);
def = &Defs.getTestDef(id); def = &Defs.getTestDef(id);
results = new std::vector<const char *>(def->numAttrs, NULL); results = new std::vector<const char *>(def->numAttrs, NULL);
} }
FingerTest(FingerPrintDef::TestID testid, FingerPrintDef &Defs) FingerTest(FingerPrintDef::TestID testid, const FingerPrintDef &Defs)
: id(testid), results(NULL) { : id(testid), results(NULL) {
def = &Defs.getTestDef(id); def = &Defs.getTestDef(id);
results = new std::vector<const char *>(def->numAttrs, NULL); results = new std::vector<const char *>(def->numAttrs, NULL);
} }
FingerTest(const FingerTest &other) : id(other.id), def(other.def), results(other.results) {}
~FingerTest() { ~FingerTest() {
// results must be freed manually // results must be freed manually
} }
void erase(); void erase();
bool str2AVal(const char *str, const char *end); bool str2AVal(const char *str, const char *end);
void setAVal(const char *attr, const char *value); void setAVal(const char *attr, const char *value);
const char *getAVal(const char *attr); const char *getAVal(const char *attr) const;
const char *getAValName(u8 index) const; const char *getAValName(u8 index) const;
const char *getTestName() const { return def->name.str; } const char *getTestName() const { return def->name.str; }
int getMaxPoints() const; int getMaxPoints() const;