diff --git a/src/ini_reader.h b/src/ini_reader.h index a6b6ffa..fe04616 100644 --- a/src/ini_reader.h +++ b/src/ini_reader.h @@ -128,7 +128,7 @@ public: /** * @brief Parse a file during initialization. */ - INIReader(const std::string &filePath) + explicit INIReader(const std::string &filePath) { parsed = false; ParseFile(filePath); diff --git a/src/interfaces.cpp b/src/interfaces.cpp index e45e152..76b9acd 100644 --- a/src/interfaces.cpp +++ b/src/interfaces.cpp @@ -134,18 +134,17 @@ const std::vector UAMatchList = { bool verGreaterEqual(const std::string &src_ver, const std::string &target_ver) { - int part_src, part_target; - string_size src_pos_beg = 0, src_pos_end = 0, target_pos_beg = 0, target_pos_end = 0; + string_size src_pos_beg = 0, src_pos_end, target_pos_beg = 0, target_pos_end; while(true) { src_pos_end = src_ver.find('.', src_pos_beg); if(src_pos_end == src_ver.npos) src_pos_end = src_ver.size(); - part_src = std::stoi(src_ver.substr(src_pos_beg, src_pos_end - src_pos_beg)); + int part_src = std::stoi(src_ver.substr(src_pos_beg, src_pos_end - src_pos_beg)); target_pos_end = target_ver.find('.', target_pos_beg); if(target_pos_end == target_ver.npos) target_pos_end = target_ver.size(); - part_target = std::stoi(target_ver.substr(target_pos_beg, target_pos_end - target_pos_beg)); + int part_target = std::stoi(target_ver.substr(target_pos_beg, target_pos_end - target_pos_beg)); if(part_src > part_target) break; else if(part_src < part_target) diff --git a/src/logger.cpp b/src/logger.cpp index 00dcb55..cfd4260 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -36,7 +36,7 @@ std::string getTime(int type) return std::string(tmpbuf); } -void writeLog(int type, std::string content, int level) +void writeLog(int type, const std::string &content, int level) { if(level > global_log_level) return; diff --git a/src/logger.h b/src/logger.h index 0c75aeb..2481da7 100644 --- a/src/logger.h +++ b/src/logger.h @@ -36,7 +36,7 @@ int makeDir(const char *path); std::string getTime(int type); void logInit(bool rpcmode); void resultInit(); -void writeLog(int type, std::string content, int level = LOG_LEVEL_VERBOSE); +void writeLog(int type, const std::string &content, int level = LOG_LEVEL_VERBOSE); void logEOF(); /* diff --git a/src/misc.cpp b/src/misc.cpp index 851d167..abf11c9 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -134,7 +134,7 @@ unsigned char ToHex(unsigned char x) unsigned char FromHex(unsigned char x) { - unsigned char y = '\0'; + unsigned char y; if (x >= 'A' && x <= 'Z') y = x - 'A' + 10; else if (x >= 'a' && x <= 'z') @@ -208,8 +208,7 @@ std::string base64_encode(const std::string &string_to_encode) unsigned int in_len = string_to_encode.size(); std::string ret; - int i = 0; - int j = 0; + int i = 0, j; unsigned char char_array_3[3]; unsigned char char_array_4[4]; @@ -256,7 +255,7 @@ std::string base64_decode(const std::string &encoded_string, bool accept_urlsafe string_size in_len = encoded_string.size(); string_size i = 0; string_size in_ = 0; - unsigned char char_array_4[4], char_array_3[3], uchar = 0; + unsigned char char_array_4[4], char_array_3[3], uchar; static unsigned char dtable[256], itable[256], table_ready = 0; std::string ret; @@ -1157,7 +1156,7 @@ std::string getFormData(const std::string &raw_data) std::string UTF8ToCodePoint(const std::string &data) { std::stringstream ss; - int charcode = 0; + int charcode; for(std::string::size_type i = 0; i < data.size(); i++) { charcode = data[i] & 0xff; diff --git a/src/misc.h b/src/misc.h index 34c9cd2..a22de37 100644 --- a/src/misc.h +++ b/src/misc.h @@ -163,7 +163,7 @@ public: template tribool(const T &value) { set(value); } - tribool(const tribool &value) { *this = value; } + explicit tribool(const tribool &value) { *this = value; } ~tribool() = default; diff --git a/src/nodemanip.cpp b/src/nodemanip.cpp index 02041c9..91c3fa3 100644 --- a/src/nodemanip.cpp +++ b/src/nodemanip.cpp @@ -19,7 +19,7 @@ void copyNodes(std::vector &source, std::vector &dest) std::move(source.begin(), source.end(), std::back_inserter(dest)); } -int addNodes(std::string link, std::vector &allNodes, int groupID, std::string proxy, string_array &exclude_remarks, string_array &include_remarks, string_array &stream_rules, string_array &time_rules, std::string &subInfo, bool authorized, string_map &request_headers) +int addNodes(std::string link, std::vector &allNodes, int groupID, const std::string &proxy, string_array &exclude_remarks, string_array &include_remarks, string_array &stream_rules, string_array &time_rules, std::string &subInfo, bool authorized, string_map &request_headers) { int linkType = -1; std::vector nodes; diff --git a/src/nodemanip.h b/src/nodemanip.h index c114bb2..4a30659 100644 --- a/src/nodemanip.h +++ b/src/nodemanip.h @@ -6,6 +6,6 @@ #include "nodeinfo.h" -int addNodes(std::string link, std::vector &allNodes, int groupID, std::string proxy, string_array &exclude_remarks, string_array &include_remarks, string_array &stream_rules, string_array &time_rules, std::string &subInfo, bool authorized, string_map &request_headers); +int addNodes(std::string link, std::vector &allNodes, int groupID, const std::string &proxy, string_array &exclude_remarks, string_array &include_remarks, string_array &stream_rules, string_array &time_rules, std::string &subInfo, bool authorized, string_map &request_headers); #endif // NODEMANIP_H_INCLUDED diff --git a/src/speedtestutil.cpp b/src/speedtestutil.cpp index d42f808..8e35e14 100644 --- a/src/speedtestutil.cpp +++ b/src/speedtestutil.cpp @@ -2031,7 +2031,6 @@ void filterNodes(std::vector &nodes, string_array &exclude_remarks, st } */ - bool excluded, included; std::vector> exclude_patterns, include_patterns; std::vector> exclude_match_data, include_match_data; unsigned int i = 0; @@ -2061,8 +2060,7 @@ void filterNodes(std::vector &nodes, string_array &exclude_remarks, st writeLog(LOG_TYPE_INFO, "Filter started."); while(iter != nodes.end()) { - excluded = false; - included = false; + bool excluded = false, included = false; for(i = 0; i < exclude_patterns.size(); i++) { rc = pcre2_match(exclude_patterns[i].get(), reinterpret_cast(iter->remarks.c_str()), iter->remarks.size(), 0, 0, exclude_match_data[i].get(), NULL); diff --git a/src/subexport.cpp b/src/subexport.cpp index 4a87d18..b230bde 100644 --- a/src/subexport.cpp +++ b/src/subexport.cpp @@ -1868,7 +1868,6 @@ std::string netchToSSSub(std::string &base_conf, std::vector &nodes, c std::string plugin, pluginopts; std::string protocol, obfs; std::string output_content; - int port; rapidjson::Document::AllocatorType &alloc = json.GetAllocator(); json.SetObject(); @@ -1897,7 +1896,7 @@ std::string netchToSSSub(std::string &base_conf, std::vector &nodes, c remark = x.remarks; hostname = x.server; - port = (unsigned short)stoi(GetMember(json, "Port")); + int port = (unsigned short)stoi(GetMember(json, "Port")); password = GetMember(json, "Password"); method = GetMember(json, "EncryptMethod"); plugin = GetMember(json, "Plugin"); diff --git a/src/templates.cpp b/src/templates.cpp index fdb9899..31481db 100644 --- a/src/templates.cpp +++ b/src/templates.cpp @@ -308,19 +308,15 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rules { case RULESET_CLASH_IPCIDR: has_ipcidr[rule_name] = true; - if(!script) - rules.emplace_back("RULE-SET," + rule_name + "_ipcidr," + rule_group); break; case RULESET_CLASH_DOMAIN: has_domain[rule_name] = true; - if(!script) - rules.emplace_back("RULE-SET," + rule_name + "_domain," + rule_group); break; case RULESET_CLASH_CLASSICAL: - if(!script) - rules.emplace_back("RULE-SET," + rule_name + "," + rule_group); break; } + if(!script) + rules.emplace_back("RULE-SET," + rule_name + "," + rule_group); groups.emplace_back(std::move(rule_name)); continue; } @@ -420,7 +416,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rules base_rule["rule-providers"][yaml_key]["url"] = url.substr(1); else base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=3&url=" + urlsafe_base64_encode(url); - base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + x + "_domain.yaml"; + base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml"; if(interval) base_rule["rule-providers"][yaml_key]["interval"] = interval; } @@ -435,7 +431,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rules base_rule["rule-providers"][yaml_key]["url"] = url.substr(1); else base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=4&url=" + urlsafe_base64_encode(url); - base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + x + "_ipcidr.yaml"; + base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml"; if(interval) base_rule["rule-providers"][yaml_key]["interval"] = interval; } @@ -448,7 +444,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rules base_rule["rule-providers"][yaml_key]["url"] = url.substr(1); else base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=6&url=" + urlsafe_base64_encode(url); - base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + x + "_classical.yaml"; + base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml"; if(interval) base_rule["rule-providers"][yaml_key]["interval"] = interval; }