From 8c431ba6da6aaa2c66f4f7260b9bb9527540ef91 Mon Sep 17 00:00:00 2001 From: fasiondog Date: Sun, 1 Nov 2020 14:01:08 +0800 Subject: [PATCH] clear cppcheck warns --- cppcheck.cppcheck | 5 ++++- hikyuu_cpp/hikyuu/KDataImp.cpp | 16 +--------------- hikyuu_cpp/hikyuu/KQuery.h | 1 + hikyuu_cpp/hikyuu/Stock.cpp | 5 ++--- hikyuu_cpp/hikyuu/StockManager.cpp | 2 +- hikyuu_cpp/hikyuu/data_driver/BaseInfoDriver.cpp | 2 ++ .../data_driver/kdata/hdf5/H5KDataDriver.cpp | 13 +++++-------- .../data_driver/kdata/mysql/KRecordTable.h | 5 +++-- .../data_driver/kdata/tdx/TdxKDataDriver.cpp | 4 ++-- hikyuu_cpp/hikyuu/datetime/Datetime.cpp | 1 - hikyuu_cpp/hikyuu/utilities/ConnectPool.h | 1 - hikyuu_cpp/hikyuu/utilities/IniParser.cpp | 6 +++--- .../hikyuu/utilities/db_connect/DBConnectBase.h | 4 ++-- .../utilities/db_connect/mysql/MySQLConnect.cpp | 3 +-- .../utilities/db_connect/mysql/MySQLConnect.h | 2 +- .../db_connect/sqlite/SQLiteConnect.cpp | 3 +-- .../utilities/db_connect/sqlite/SQLiteConnect.h | 2 +- .../hikyuu/utilities/task/StealTaskBase.cpp | 2 +- hikyuu_cpp/hikyuu/utilities/task/StealTaskBase.h | 2 +- .../hikyuu/utilities/task/StealTaskGroup.cpp | 6 ------ 20 files changed, 32 insertions(+), 53 deletions(-) diff --git a/cppcheck.cppcheck b/cppcheck.cppcheck index a5638bcc7..82afb7661 100644 --- a/cppcheck.cppcheck +++ b/cppcheck.cppcheck @@ -6,6 +6,7 @@ true false 10 + 100 @@ -13,7 +14,9 @@ boost - noExplicitConstructor unusedFunction + ConfigurationNotChecked + toomanyconfigs + unknownMacro diff --git a/hikyuu_cpp/hikyuu/KDataImp.cpp b/hikyuu_cpp/hikyuu/KDataImp.cpp index a4361cc5d..db0692348 100644 --- a/hikyuu_cpp/hikyuu/KDataImp.cpp +++ b/hikyuu_cpp/hikyuu/KDataImp.cpp @@ -13,7 +13,7 @@ namespace hku { -KDataImp::KDataImp() : m_start(0), m_end(0) {} +KDataImp::KDataImp() : m_start(0), m_end(0), m_have_pos_in_stock(false) {} KDataImp::KDataImp(const Stock& stock, const KQuery& query) : m_query(query), m_stock(stock), m_start(0), m_end(0), m_have_pos_in_stock(false) { @@ -64,20 +64,6 @@ KDataImp::KDataImp(const Stock& stock, const KQuery& query) KDataImp::~KDataImp() {} -/*bool KDataImp::empty() { - if (!m_have_pos_in_stock) { - _getPosInStock(); - } - return m_start == m_end ? true : false; -} - -size_t KDataImp::size() { - if (!m_have_pos_in_stock) { - _getPosInStock(); - } - return m_end - m_start; -}*/ - size_t KDataImp::startPos() { if (!m_have_pos_in_stock) { _getPosInStock(); diff --git a/hikyuu_cpp/hikyuu/KQuery.h b/hikyuu_cpp/hikyuu/KQuery.h index 63a6187b3..c51e3c6c9 100644 --- a/hikyuu_cpp/hikyuu/KQuery.h +++ b/hikyuu_cpp/hikyuu/KQuery.h @@ -236,6 +236,7 @@ bool operator==(const KQuery&, const KQuery&); bool operator!=(const KQuery&, const KQuery&); inline bool operator!=(const KQuery& q1, const KQuery& q2) { + // cppcheck-suppress [mismatchingContainerExpression] if (q1.start() != q2.start() || q1.end() != q2.end() || q1.queryType() != q2.queryType() || q1.kType() != q2.kType() || q1.recoverType() != q2.recoverType()) { return true; diff --git a/hikyuu_cpp/hikyuu/Stock.cpp b/hikyuu_cpp/hikyuu/Stock.cpp index 9fd0b28ea..92cda5ae9 100644 --- a/hikyuu_cpp/hikyuu/Stock.cpp +++ b/hikyuu_cpp/hikyuu/Stock.cpp @@ -466,7 +466,7 @@ bool Stock::_getIndexRangeByDateFromBuffer(const KQuery& query, size_t& out_star } const KRecordList& kdata = *(m_data->pKData[query.kType()]); - size_t mid, low = 0, high = total - 1; + size_t mid = total, low = 0, high = total - 1; size_t startpos, endpos; while (low <= high) { if (query.startDatetime() > kdata[high].datetime) { @@ -560,10 +560,9 @@ KRecord Stock::getKRecord(const Datetime& datetime, KQuery::KType ktype) const { // string ktype(inktype); // to_upper(ktype); - KQuery query = KQueryByDate(datetime, datetime + Minutes(1), ktype); - size_t startix = 0, endix = 0; if (m_data->pKData.find(ktype) != m_data->pKData.end() || m_kdataDriver->isIndexFirst()) { + size_t startix = 0, endix = 0; return getIndexRange(query, startix, endix) ? getKRecord(startix, ktype) : Null(); } diff --git a/hikyuu_cpp/hikyuu/StockManager.cpp b/hikyuu_cpp/hikyuu/StockManager.cpp index 769beee90..d309a2a23 100644 --- a/hikyuu_cpp/hikyuu/StockManager.cpp +++ b/hikyuu_cpp/hikyuu/StockManager.cpp @@ -347,9 +347,9 @@ BlockList StockManager::getBlockList() { DatetimeList StockManager::getTradingCalendar(const KQuery& query, const string& market) { Stock stock = getStock("SH000001"); - size_t start_ix = 0, end_ix = 0; DatetimeList result; if (query.queryType() == KQuery::INDEX) { + size_t start_ix = 0, end_ix = 0; if (stock.getIndexRange(query, start_ix, end_ix)) { result = stock.getDatetimeList(KQuery(start_ix, end_ix, query.kType())); } diff --git a/hikyuu_cpp/hikyuu/data_driver/BaseInfoDriver.cpp b/hikyuu_cpp/hikyuu/data_driver/BaseInfoDriver.cpp index 7a69a1530..119c0d81c 100644 --- a/hikyuu_cpp/hikyuu/data_driver/BaseInfoDriver.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/BaseInfoDriver.cpp @@ -57,6 +57,8 @@ bool BaseInfoDriver::init(const Parameter& params) { if (!checkType()) { return false; } + + HKU_INFO("Using {} BaseInfoDriver", name()); return _init(); } diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.cpp b/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.cpp index 06cb3172d..9b3337569 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.cpp @@ -46,7 +46,6 @@ class Hdf5FileCloser { h5file->close(); // HKU_INFO("Closed {}", filename); delete h5file; - h5file = nullptr; } } }; @@ -461,7 +460,7 @@ bool H5KDataDriver::_getOtherIndexRangeByDate(const string& market, const string return false; } - size_t mid, low = 0, high = total - 1; + size_t mid = total, low = 0, high = total - 1; uint64_t startDatetime = query.startDatetime().number(); H5IndexRecord h5record; while (low <= high) { @@ -976,10 +975,9 @@ TransList H5KDataDriver::_getTransList(const string& market, const string& code, TransRecord record; result.reserve(total + 2); - uint64_t number = 0, second = 0; for (hsize_t i = 0; i < total; i++) { - number = pBuf[i].datetime / 100; - second = pBuf[i].datetime - number * 100; + uint64_t number = pBuf[i].datetime / 100; + uint64_t second = pBuf[i].datetime - number * 100; Datetime d(number); record.datetime = Datetime(d.year(), d.month(), d.day(), d.hour(), d.minute(), second); record.price = price_t(pBuf[i].price) * 0.001; @@ -1128,10 +1126,9 @@ TransList H5KDataDriver::_getTransList(const string& market, const string& code, TransRecord record; result.reserve(total + 2); - uint64_t number = 0, second = 0; for (hsize_t i = 0; i < total; i++) { - number = pBuf[i].datetime / 100; - second = pBuf[i].datetime - number * 100; + uint64_t number = pBuf[i].datetime / 100; + uint64_t second = pBuf[i].datetime - number * 100; Datetime d(number); record.datetime = Datetime(d.year(), d.month(), d.day(), d.hour(), d.minute(), second); record.price = price_t(pBuf[i].price) * 0.001; diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/mysql/KRecordTable.h b/hikyuu_cpp/hikyuu/data_driver/kdata/mysql/KRecordTable.h index 04ee25852..ebc466f6c 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/mysql/KRecordTable.h +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/mysql/KRecordTable.h @@ -19,7 +19,8 @@ class KRecordTable { : m_date(0), m_open(0.0), m_high(0.0), m_low(0.0), m_close(0.0), m_amount(0.0), m_count(0.0) {} KRecordTable(const string& market, const string& code, const KQuery::KType& ktype) - : m_code(code), + : m_db_name(fmt::format("{}_{}", market, KQuery::getKTypeName(ktype))), + m_code(code), m_date(0), m_open(0.0), m_high(0.0), @@ -27,7 +28,7 @@ class KRecordTable { m_close(0.0), m_amount(0.0), m_count(0.0) { - m_db_name = fmt::format("{}_{}", market, KQuery::getKTypeName(ktype)); + // m_db_name = fmt::format("{}_{}", market, KQuery::getKTypeName(ktype)); to_lower(m_db_name); }; diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.cpp b/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.cpp index 979d5a953..ae4a79c6c 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.cpp @@ -224,7 +224,7 @@ bool TdxKDataDriver::_getDayIndexRangeByDate(const string& market, const string& struct TdxDayData tdx_data; size_t len = sizeof(tdx_data); - size_t mid, low = 0, high = total - 1; + size_t mid = total, low = 0, high = total - 1; size_t startpos = 0, endpos = 0; while (low <= high) { file.seekg(high * len, file.beg); @@ -329,7 +329,7 @@ bool TdxKDataDriver::_getMinIndexRangeByDate(const string& market, const string& struct TdxMinData tdx_data; size_t len = sizeof(tdx_data); - size_t mid, low = 0, high = total - 1; + size_t mid = total, low = 0, high = total - 1; size_t startpos = 0, endpos = 0; while (low <= high) { file.seekg(high * len, file.beg); diff --git a/hikyuu_cpp/hikyuu/datetime/Datetime.cpp b/hikyuu_cpp/hikyuu/datetime/Datetime.cpp index 91ace0cdd..b397ba906 100644 --- a/hikyuu_cpp/hikyuu/datetime/Datetime.cpp +++ b/hikyuu_cpp/hikyuu/datetime/Datetime.cpp @@ -99,7 +99,6 @@ std::string Datetime::str() const { return "+infinity"; } - std::string result; double microseconds = millisecond() * 1000 + microsecond(); // 和 python datetime 打印方式保持一致 diff --git a/hikyuu_cpp/hikyuu/utilities/ConnectPool.h b/hikyuu_cpp/hikyuu/utilities/ConnectPool.h index 7cc90cc68..9665ec814 100644 --- a/hikyuu_cpp/hikyuu/utilities/ConnectPool.h +++ b/hikyuu_cpp/hikyuu/utilities/ConnectPool.h @@ -89,7 +89,6 @@ class ConnectPool { m_connectList.push(p); } else { delete p; - p = nullptr; m_count--; } } else { diff --git a/hikyuu_cpp/hikyuu/utilities/IniParser.cpp b/hikyuu_cpp/hikyuu/utilities/IniParser.cpp index 42d72b6df..0e0f99b02 100644 --- a/hikyuu_cpp/hikyuu/utilities/IniParser.cpp +++ b/hikyuu_cpp/hikyuu/utilities/IniParser.cpp @@ -259,7 +259,7 @@ int IniParser::getInt(const std::string& section, const std::string& option, std::string value_str = get(section, option, default_str); remain = 0; - result = std::stoi(value_str, &remain); + result = std::stoi(value_str, &remain); // cppcheck-suppress redundantAssignment if (remain != value_str.size()) { throw(std::invalid_argument("This option cannot be converted to an integer! " + value_str)); } @@ -292,7 +292,7 @@ float IniParser::getFloat(const std::string& section, const std::string& option, std::string value_str = get(section, option, default_str); remain = 0; - result = std::stof(value_str, &remain); + result = std::stof(value_str, &remain); // cppcheck-suppress redundantAssignment if (remain != value_str.size()) { throw(std::invalid_argument("This option cannot be converted to an float! " + value_str)); } @@ -325,7 +325,7 @@ double IniParser::getDouble(const std::string& section, const std::string& optio std::string value_str = get(section, option, default_str); remain = 0; - result = std::stod(value_str, &remain); + result = std::stod(value_str, &remain); // cppcheck-suppress redundantAssignment if (remain != value_str.size()) { throw(std::invalid_argument("This option cannot be converted to an double! " + value_str)); } diff --git a/hikyuu_cpp/hikyuu/utilities/db_connect/DBConnectBase.h b/hikyuu_cpp/hikyuu/utilities/db_connect/DBConnectBase.h index 619d7df11..869820c2a 100644 --- a/hikyuu_cpp/hikyuu/utilities/db_connect/DBConnectBase.h +++ b/hikyuu_cpp/hikyuu/utilities/db_connect/DBConnectBase.h @@ -28,7 +28,7 @@ class HKU_API DBConnectBase { * 构造函数 * @param param 数据库连接参数 */ - explicit DBConnectBase(const Parameter& param) noexcept; + explicit DBConnectBase(const Parameter& param); virtual ~DBConnectBase() = default; //------------------------------------------------------------------------- @@ -176,7 +176,7 @@ typedef shared_ptr DBConnectPtr; // inline方法实现 //------------------------------------------------------------------------- -inline DBConnectBase::DBConnectBase(const Parameter& param) noexcept : m_params(param) {} +inline DBConnectBase::DBConnectBase(const Parameter& param) : m_params(param) {} inline int DBConnectBase::queryInt(const string& query) { SQLStatementPtr st = getStatement(query); diff --git a/hikyuu_cpp/hikyuu/utilities/db_connect/mysql/MySQLConnect.cpp b/hikyuu_cpp/hikyuu/utilities/db_connect/mysql/MySQLConnect.cpp index 945dfbb89..5e376f774 100755 --- a/hikyuu_cpp/hikyuu/utilities/db_connect/mysql/MySQLConnect.cpp +++ b/hikyuu_cpp/hikyuu/utilities/db_connect/mysql/MySQLConnect.cpp @@ -11,8 +11,7 @@ namespace hku { -MySQLConnect::MySQLConnect(const Parameter& param) noexcept -: DBConnectBase(param), m_mysql(nullptr) { +MySQLConnect::MySQLConnect(const Parameter& param) : DBConnectBase(param), m_mysql(nullptr) { m_mysql = new MYSQL; try { HKU_CHECK(m_mysql, "Failed new MYSQL instance!"); diff --git a/hikyuu_cpp/hikyuu/utilities/db_connect/mysql/MySQLConnect.h b/hikyuu_cpp/hikyuu/utilities/db_connect/mysql/MySQLConnect.h index f0c2d5c94..3c70b80ff 100755 --- a/hikyuu_cpp/hikyuu/utilities/db_connect/mysql/MySQLConnect.h +++ b/hikyuu_cpp/hikyuu/utilities/db_connect/mysql/MySQLConnect.h @@ -24,7 +24,7 @@ namespace hku { class HKU_API MySQLConnect : public DBConnectBase { public: - MySQLConnect(const Parameter& param) noexcept; + MySQLConnect(const Parameter& param); virtual ~MySQLConnect(); virtual bool ping() override; diff --git a/hikyuu_cpp/hikyuu/utilities/db_connect/sqlite/SQLiteConnect.cpp b/hikyuu_cpp/hikyuu/utilities/db_connect/sqlite/SQLiteConnect.cpp index 7e3047501..7f1fa6ce4 100644 --- a/hikyuu_cpp/hikyuu/utilities/db_connect/sqlite/SQLiteConnect.cpp +++ b/hikyuu_cpp/hikyuu/utilities/db_connect/sqlite/SQLiteConnect.cpp @@ -21,8 +21,7 @@ static int sqlite_busy_call_back(void* ptr, int count) { return 1; } -SQLiteConnect::SQLiteConnect(const Parameter& param) noexcept -: DBConnectBase(param), m_db(nullptr) { +SQLiteConnect::SQLiteConnect(const Parameter& param) : DBConnectBase(param), m_db(nullptr) { try { m_dbname = getParam("db"); int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_NOMUTEX; diff --git a/hikyuu_cpp/hikyuu/utilities/db_connect/sqlite/SQLiteConnect.h b/hikyuu_cpp/hikyuu/utilities/db_connect/sqlite/SQLiteConnect.h index 68aad3589..ace592bfc 100644 --- a/hikyuu_cpp/hikyuu/utilities/db_connect/sqlite/SQLiteConnect.h +++ b/hikyuu_cpp/hikyuu/utilities/db_connect/sqlite/SQLiteConnect.h @@ -36,7 +36,7 @@ class HKU_API SQLiteConnect : public DBConnectBase { * (具体可参考 SQLite 帮助) * */ - explicit SQLiteConnect(const Parameter& param) noexcept; + explicit SQLiteConnect(const Parameter& param); /** 析构函数 */ virtual ~SQLiteConnect(); diff --git a/hikyuu_cpp/hikyuu/utilities/task/StealTaskBase.cpp b/hikyuu_cpp/hikyuu/utilities/task/StealTaskBase.cpp index d9f004c32..6c15d2faf 100644 --- a/hikyuu_cpp/hikyuu/utilities/task/StealTaskBase.cpp +++ b/hikyuu_cpp/hikyuu/utilities/task/StealTaskBase.cpp @@ -14,7 +14,7 @@ namespace hku { -StealTaskBase::StealTaskBase() : m_done(false) {} +StealTaskBase::StealTaskBase() : m_done(false), m_group(nullptr) {} StealTaskBase::~StealTaskBase() {} diff --git a/hikyuu_cpp/hikyuu/utilities/task/StealTaskBase.h b/hikyuu_cpp/hikyuu/utilities/task/StealTaskBase.h index e0f04480c..16dd81c1c 100644 --- a/hikyuu_cpp/hikyuu/utilities/task/StealTaskBase.h +++ b/hikyuu_cpp/hikyuu/utilities/task/StealTaskBase.h @@ -81,7 +81,7 @@ class StopTask : public StealTaskBase { StopTask() {} virtual ~StopTask() {} - void run(){}; + void run() override{}; }; } // namespace hku diff --git a/hikyuu_cpp/hikyuu/utilities/task/StealTaskGroup.cpp b/hikyuu_cpp/hikyuu/utilities/task/StealTaskGroup.cpp index 29de256c2..1f5a11ac9 100644 --- a/hikyuu_cpp/hikyuu/utilities/task/StealTaskGroup.cpp +++ b/hikyuu_cpp/hikyuu/utilities/task/StealTaskGroup.cpp @@ -61,17 +61,11 @@ void StealTaskGroup::join() { } // 向主任务队列插入“停止”任务 - std::vector stopTaskList; for (auto i = 0; i < m_runnerNum; i++) { auto stopTask = std::make_shared(); m_master_queue->push(stopTask); } - // 等待“停止”任务被执行 - for (auto& task : stopTaskList) { - task->join(); - } - m_done = true; RunnerList::iterator runnerIter;