clang-tidy, part 1

This commit is contained in:
Alexey Milovidov 2020-03-09 00:04:10 +03:00
parent 1cba0eaceb
commit 7a7e45e248
17 changed files with 39 additions and 48 deletions

View File

@ -59,7 +59,7 @@ DateLUTImpl::DateLUTImpl(const std::string & time_zone_)
time_t start_of_day = DATE_LUT_MIN;
cctz::time_zone cctz_time_zone;
if (!cctz::load_time_zone(time_zone.data(), &cctz_time_zone))
if (!cctz::load_time_zone(time_zone, &cctz_time_zone))
throw Poco::Exception("Cannot load time zone " + time_zone_);
cctz::time_zone::absolute_lookup start_of_epoch_lookup = cctz_time_zone.lookup(std::chrono::system_clock::from_time_t(start_of_day));

View File

@ -341,7 +341,7 @@ JSON::Pos JSON::skipArray() const
if (*pos == ']')
return ++pos;
while (1)
while (true)
{
pos = JSON(pos, ptr_end, level + 1).skipElement();
@ -373,7 +373,7 @@ JSON::Pos JSON::skipObject() const
if (*pos == '}')
return ++pos;
while (1)
while (true)
{
pos = JSON(pos, ptr_end, level + 1).skipNameValuePair();

View File

@ -108,6 +108,6 @@ unsigned int sumburConsistentHash(unsigned int hashed_int, unsigned int capacity
if (L / i - h < part) return n - 1;
}
}
} while(0);
} while(false);
return n - 1;
}

View File

@ -593,7 +593,7 @@ void debugIncreaseOOMScore() {}
void BaseDaemon::initialize(Application & self)
{
closeFDs();
task_manager.reset(new Poco::TaskManager);
task_manager = std::make_unique<Poco::TaskManager>();
ServerApplication::initialize(self);
/// now highest priority (lowest value) is PRIO_APPLICATION = -100, we want higher!
@ -778,7 +778,7 @@ void BaseDaemon::initializeTerminationAndSignalProcessing()
signal_pipe.setNonBlocking();
signal_pipe.tryIncreaseSize(1 << 20);
signal_listener.reset(new SignalListener(*this));
signal_listener = std::make_unique<SignalListener>(*this);
signal_listener_thread.start(*signal_listener);
}
@ -839,9 +839,7 @@ void BaseDaemon::defineOptions(Poco::Util::OptionSet& _options)
bool isPidRunning(pid_t pid)
{
if (getpgid(pid) >= 0)
return 1;
return 0;
return getpgid(pid) >= 0;
}
BaseDaemon::PID::PID(const std::string & file_)

View File

@ -30,7 +30,7 @@ GraphiteWriter::GraphiteWriter(const std::string & config_name, const std::strin
root_path += hostname_in_path;
}
if (sub_path.size())
if (!sub_path.empty())
{
if (!root_path.empty())
root_path += ".";

View File

@ -198,7 +198,7 @@ public:
return description;
}
void removeConnection(Connection * data);
void removeConnection(Connection * connection);
protected:
/// Number of MySQL connections which are created at launch.

View File

@ -38,7 +38,7 @@ static std::string getPoolEntryName(const Poco::Util::AbstractConfiguration & co
if (!shared)
return "";
std::string entry_name = "";
std::string entry_name;
std::string host = config.getString(config_name + ".host", "");
std::string port = config.getString(config_name + ".port", "");
std::string user = config.getString(config_name + ".user", "");

View File

@ -10,16 +10,16 @@ static bool startsWith(const std::string & s, const char * prefix)
using namespace mysqlxx;
PoolWithFailover::PoolWithFailover(const Poco::Util::AbstractConfiguration & cfg,
PoolWithFailover::PoolWithFailover(const Poco::Util::AbstractConfiguration & config,
const std::string & config_name, const unsigned default_connections,
const unsigned max_connections, const size_t max_tries)
: max_tries(max_tries)
{
shareable = cfg.getBool(config_name + ".share_connection", false);
if (cfg.has(config_name + ".replica"))
shareable = config.getBool(config_name + ".share_connection", false);
if (config.has(config_name + ".replica"))
{
Poco::Util::AbstractConfiguration::Keys replica_keys;
cfg.keys(config_name, replica_keys);
config.keys(config_name, replica_keys);
for (const auto & replica_config_key : replica_keys)
{
/// There could be another elements in the same level in configuration file, like "password", "port"...
@ -27,17 +27,17 @@ PoolWithFailover::PoolWithFailover(const Poco::Util::AbstractConfiguration & cfg
{
std::string replica_name = config_name + "." + replica_config_key;
int priority = cfg.getInt(replica_name + ".priority", 0);
int priority = config.getInt(replica_name + ".priority", 0);
replicas_by_priority[priority].emplace_back(
std::make_shared<Pool>(cfg, replica_name, default_connections, max_connections, config_name.c_str()));
std::make_shared<Pool>(config, replica_name, default_connections, max_connections, config_name.c_str()));
}
}
}
else
{
replicas_by_priority[0].emplace_back(
std::make_shared<Pool>(cfg, config_name, default_connections, max_connections));
std::make_shared<Pool>(config, config_name, default_connections, max_connections));
}
}

View File

@ -11,7 +11,7 @@
namespace mysqlxx
{
Query::Query(Connection * conn_, const std::string & query_string) : std::ostream(0), conn(conn_)
Query::Query(Connection * conn_, const std::string & query_string) : std::ostream(nullptr), conn(conn_)
{
/// Важно в случае, если Query используется не из того же потока, что Connection.
mysql_thread_init();
@ -27,7 +27,7 @@ Query::Query(Connection * conn_, const std::string & query_string) : std::ostrea
imbue(std::locale::classic());
}
Query::Query(const Query & other) : std::ostream(0), conn(other.conn)
Query::Query(const Query & other) : std::ostream(nullptr), conn(other.conn)
{
/// Важно в случае, если Query используется не из того же потока, что Connection.
mysql_thread_init();

View File

@ -847,7 +847,6 @@ bool Dwarf::LineNumberVM::nextDefineFile(std::string_view & program, FileName &
}
program.remove_prefix(length);
continue;
}
return false;

View File

@ -186,7 +186,7 @@ private:
public:
LineNumberVM(std::string_view data, std::string_view compilationDirectory);
bool findAddress(uintptr_t address, Path & file, uint64_t & line);
bool findAddress(uintptr_t target, Path & file, uint64_t & line);
private:
void init();
@ -210,8 +210,8 @@ private:
// otherwise, 1-based index in the list of include directories
uint64_t directoryIndex;
};
// Read one FileName object, remove_prefix sp
static bool readFileName(std::string_view & sp, FileName & fn);
// Read one FileName object, remove_prefix program
static bool readFileName(std::string_view & program, FileName & fn);
// Get file name at given index; may be in the initial table
// (fileNames_) or defined using DW_LNE_define_file (and we reexecute
@ -259,8 +259,8 @@ private:
uint64_t discriminator_;
};
// Read an abbreviation from a std::string_view, return true if at end; remove_prefix sp
static bool readAbbreviation(std::string_view & sp, DIEAbbreviation & abbr);
// Read an abbreviation from a std::string_view, return true if at end; remove_prefix section
static bool readAbbreviation(std::string_view & section, DIEAbbreviation & abbr);
// Get abbreviation corresponding to a code, in the chunk starting at
// offset in the .debug_abbrev section

View File

@ -25,10 +25,6 @@ namespace ErrorCodes
}
Exception::Exception()
{
}
Exception::Exception(const std::string & msg, int code)
: Poco::Exception(msg, code)
{
@ -82,12 +78,12 @@ std::string Exception::getStackTraceString() const
}
std::string errnoToString(int code, int e)
std::string errnoToString(int code, int the_errno)
{
const size_t buf_size = 128;
char buf[buf_size];
#ifndef _GNU_SOURCE
int rc = strerror_r(e, buf, buf_size);
int rc = strerror_r(the_errno, buf, buf_size);
#ifdef __APPLE__
if (rc != 0 && rc != EINVAL)
#else
@ -100,16 +96,16 @@ std::string errnoToString(int code, int e)
strcpy(buf, unknown_message);
strcpy(buf + strlen(unknown_message), code_str);
}
return "errno: " + toString(e) + ", strerror: " + std::string(buf);
return "errno: " + toString(the_errno) + ", strerror: " + std::string(buf);
#else
(void)code;
return "errno: " + toString(e) + ", strerror: " + std::string(strerror_r(e, buf, sizeof(buf)));
return "errno: " + toString(the_errno) + ", strerror: " + std::string(strerror_r(the_errno, buf, sizeof(buf)));
#endif
}
void throwFromErrno(const std::string & s, int code, int e)
void throwFromErrno(const std::string & s, int code, int the_errno)
{
throw ErrnoException(s + ", " + errnoToString(code, e), code, e);
throw ErrnoException(s + ", " + errnoToString(code, the_errno), code, the_errno);
}
void throwFromErrnoWithPath(const std::string & s, const std::string & path, int code, int the_errno)
@ -267,9 +263,9 @@ int getCurrentExceptionCode()
void rethrowFirstException(const Exceptions & exceptions)
{
for (size_t i = 0, size = exceptions.size(); i < size; ++i)
if (exceptions[i])
std::rethrow_exception(exceptions[i]);
for (auto & exception : exceptions)
if (exception)
std::rethrow_exception(exception);
}

View File

@ -21,7 +21,7 @@ namespace ErrorCodes
class Exception : public Poco::Exception
{
public:
Exception();
Exception() = default;
Exception(const std::string & msg, int code);
enum CreateFromPocoTag { CreateFromPoco };

View File

@ -103,7 +103,7 @@ void FileChecker::save() const
/// `escapeForFileName` is not really needed. But it is left for compatibility with the old code.
writeJSONString(escapeForFileName(it->first), *out, settings);
writeString(":{\"size\":\"", *out);
writeString(R"(:{"size":")", *out);
writeIntText(it->second, *out);
writeString("\"}", *out);
}
@ -136,8 +136,8 @@ void FileChecker::load(Map & local_map, const String & path) const
JSON json(out.str());
JSON files = json["yandex"];
for (const JSON name_value : files)
local_map[unescapeForFileName(name_value.getName())] = name_value.getValue()["size"].toUInt();
for (const JSON file : files) // NOLINT
local_map[unescapeForFileName(file.getName())] = file.getValue()["size"].toUInt();
}
}

View File

@ -12,8 +12,6 @@ namespace ErrorCodes
extern const int SYNTAX_ERROR;
}
Macros::Macros() {}
Macros::Macros(const Poco::Util::AbstractConfiguration & config, const String & root_key)
{
Poco::Util::AbstractConfiguration::Keys keys;

View File

@ -23,7 +23,7 @@ namespace DB
class Macros
{
public:
Macros();
Macros() = default;
Macros(const Poco::Util::AbstractConfiguration & config, const String & key);
/** Replace the substring of the form {macro_name} with the value for macro_name, obtained from the config file.

View File

@ -361,7 +361,7 @@ bool OptimizedRegularExpressionImpl<thread_safe>::match(const char * subject, si
{
match.offset = pos - haystack;
match.length = required_substring.size();
return 1;
return true;
}
}
else