From: Jelte Jansen Date: Thu, 27 Sep 2012 14:00:48 +0000 (+0200) Subject: [2278] A number of cppcheck fixes X-Git-Tag: trac2351_base~7^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=718888317b9fb6b24c20d8d417ea540ff23257c5;p=thirdparty%2Fkea.git [2278] A number of cppcheck fixes and whitespace things, while i was there --- diff --git a/src/lib/cc/data.cc b/src/lib/cc/data.cc index 6ec243a1a0..47b1eb1fa4 100644 --- a/src/lib/cc/data.cc +++ b/src/lib/cc/data.cc @@ -413,7 +413,7 @@ from_stringstream_number(std::istream &in, int &pos) { isc_throw(JSONError, std::string("Number overflow: ") + number); } } - + if (is_double) { return (Element::create(d)); } else { @@ -501,7 +501,7 @@ from_stringstream_map(std::istream &in, const std::string& file, int& line, ConstElementPtr value = Element::fromJSON(in, file, line, pos); map->set(key, value); - + skip_to(in, file, line, pos, ",}", WHITESPACE); c = in.get(); pos++; @@ -942,7 +942,7 @@ removeIdentical(ConstElementPtr a, ConstElementPtr b) { if (!b) { return (result); } - + if (a->getType() != Element::map || b->getType() != Element::map) { isc_throw(TypeError, "Non-map Elements passed to removeIdentical"); } @@ -965,7 +965,7 @@ merge(ElementPtr element, ConstElementPtr other) { other->getType() != Element::map) { isc_throw(TypeError, "merge arguments not MapElements"); } - + const std::map& m = other->mapValue(); for (std::map::const_iterator it = m.begin(); it != m.end() ; ++it) { diff --git a/src/lib/dhcp/tests/iface_mgr_unittest.cc b/src/lib/dhcp/tests/iface_mgr_unittest.cc index 2c7b86b182..462910bd81 100644 --- a/src/lib/dhcp/tests/iface_mgr_unittest.cc +++ b/src/lib/dhcp/tests/iface_mgr_unittest.cc @@ -1096,7 +1096,7 @@ void parse_ifconfig(const std::string& textFile, IfaceMgr::IfaceCollection& ifac addr = addr.substr(0, addr.find_first_of(" ")); IOAddress a(addr); iface->addAddress(a); - } else if(line.find("Metric")) { + } else if(line.find("Metric") != string::npos) { // flags if (line.find("UP") != string::npos) { iface->flag_up_ = true; diff --git a/src/lib/dns/benchmarks/message_renderer_bench.cc b/src/lib/dns/benchmarks/message_renderer_bench.cc index 6376498087..abf3192690 100644 --- a/src/lib/dns/benchmarks/message_renderer_bench.cc +++ b/src/lib/dns/benchmarks/message_renderer_bench.cc @@ -39,7 +39,7 @@ public: renderer_(NULL), names_(names) {} - MessageRendererBenchMark() { + ~MessageRendererBenchMark() { delete renderer_; } unsigned int run() { diff --git a/src/lib/dns/benchmarks/rdatarender_bench.cc b/src/lib/dns/benchmarks/rdatarender_bench.cc index 38ee2ace7c..65576ee645 100644 --- a/src/lib/dns/benchmarks/rdatarender_bench.cc +++ b/src/lib/dns/benchmarks/rdatarender_bench.cc @@ -42,9 +42,10 @@ template class RdataRenderBenchMark { public: RdataRenderBenchMark(const vector& dataset) : - dataset_(dataset) + dataset_(dataset), + renderer_(NULL) {} - RdataRenderBenchMark() { + ~RdataRenderBenchMark() { delete renderer_; } unsigned int run() { diff --git a/src/lib/dns/python/edns_python.cc b/src/lib/dns/python/edns_python.cc index 8f0f1a4213..e9d54c1a26 100644 --- a/src/lib/dns/python/edns_python.cc +++ b/src/lib/dns/python/edns_python.cc @@ -269,7 +269,6 @@ EDNS_createFromRR(const s_EDNS* null_self, PyObject* args) { const PyObject* rrtype; const PyObject* rrttl; const PyObject* rdata; - s_EDNS* edns_obj = NULL; assert(null_self == NULL); @@ -277,7 +276,7 @@ EDNS_createFromRR(const s_EDNS* null_self, PyObject* args) { &rrclass_type, &rrclass, &rrtype_type, &rrtype, &rrttl_type, &rrttl, &rdata_type, &rdata)) { uint8_t extended_rcode; - edns_obj = PyObject_New(s_EDNS, &edns_type); + s_EDNS* edns_obj = PyObject_New(s_EDNS, &edns_type); if (edns_obj == NULL) { return (NULL); } diff --git a/src/lib/dns/rdata/generic/afsdb_18.cc b/src/lib/dns/rdata/generic/afsdb_18.cc index 6afc4de51e..ec76ee0e00 100644 --- a/src/lib/dns/rdata/generic/afsdb_18.cc +++ b/src/lib/dns/rdata/generic/afsdb_18.cc @@ -57,7 +57,6 @@ AFSDB::AFSDB(const std::string& afsdb_str) : try { const uint32_t subtype = tokenToNum(getToken(iss)); const Name servername(getToken(iss)); - string server; if (!iss.eof()) { isc_throw(InvalidRdataText, "Unexpected input for AFSDB" diff --git a/src/lib/dns/tests/rrparamregistry_unittest.cc b/src/lib/dns/tests/rrparamregistry_unittest.cc index d2bec5c0d4..7b0455d2b0 100644 --- a/src/lib/dns/tests/rrparamregistry_unittest.cc +++ b/src/lib/dns/tests/rrparamregistry_unittest.cc @@ -60,7 +60,7 @@ protected: // we assume class/type numbers are officially unassigned. If not we'll // need to update the test cases. - static const uint16_t test_class_code = 65533; + static const uint16_t test_class_code = 65533; static const uint16_t test_type_code = 65534; static const string test_class_str; static const string test_type_str; @@ -77,7 +77,7 @@ TEST_F(RRParamRegistryTest, addRemove) { // the first removal attempt should succeed EXPECT_TRUE(RRParamRegistry::getRegistry().removeType(test_type_code)); - // then toText() should treat it as an "unknown" + // then toText() should treat it as an "unknown" EXPECT_EQ(test_type_unknown_str, RRType(test_type_code).toText()); // attempt of removing non-existent mapping should result in 'false' EXPECT_FALSE(RRParamRegistry::getRegistry().removeType(test_type_code)); diff --git a/src/lib/log/compiler/message.cc b/src/lib/log/compiler/message.cc index 86c5f200e9..ef62b2f331 100644 --- a/src/lib/log/compiler/message.cc +++ b/src/lib/log/compiler/message.cc @@ -109,11 +109,13 @@ currentTime() { // Get a text representation of the current time. time_t curtime; time(&curtime); - char* buffer = ctime(&curtime); + struct tm* timeinfo; + timeinfo = localtime(&curtime); - // Convert to string and strip out the trailing newline - string current_time = buffer; - return (isc::util::str::trim(current_time)); + char buffer[80]; + strftime(buffer, 80, "%a %b %d %Y %H:%M", timeinfo); + + return (std::string(buffer)); } diff --git a/src/lib/log/tests/logger_example.cc b/src/lib/log/tests/logger_example.cc index 6f95e5d1a3..08c9084ddd 100644 --- a/src/lib/log/tests/logger_example.cc +++ b/src/lib/log/tests/logger_example.cc @@ -118,7 +118,6 @@ int main(int argc, char** argv) { LoggerSpecification cur_spec(ROOT_NAME);// Current specification OutputOption cur_opt; // Current output option vector loggers; // Set of logger specifications - vector options; // Output options for logger std::string severity; // Severity set for logger // Initialize logging system - set the root logger name. diff --git a/src/lib/util/hash/sha1.cc b/src/lib/util/hash/sha1.cc index 091e29316a..1fdadfdfcf 100644 --- a/src/lib/util/hash/sha1.cc +++ b/src/lib/util/hash/sha1.cc @@ -48,7 +48,7 @@ * merchantability of this software or the suitability of this * software for any particular purpose. It is provided "as is" * without express or implied warranty of any kind. - * + * */ #include @@ -79,7 +79,7 @@ SHA_Parity(const uint32_t x, const uint32_t y, const uint32_t z) { return ((x) ^ (y) ^ (z)); } -static inline int +static inline int SHA1CircularShift(uint8_t bits, uint32_t word) { return ((word << bits) | (word >> (32 - bits))); }