-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix cppcoreguidelines-narrowing-conversions warning reported by clang-tidy #1159
Fix cppcoreguidelines-narrowing-conversions warning reported by clang-tidy #1159
Conversation
src/server/redis_reply.h
Outdated
template <typename IntegerType> | ||
std::string Integer(IntegerType data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually you can implement this template function in the header directly to avoid explicit instantiations.
…ons-warning-reported-by-clang-tidy
…ons-warning-reported-by-clang-tidy
src/common/string_util.cc
Outdated
@@ -121,7 +121,7 @@ int StringMatch(const std::string &pattern, const std::string &in, int nocase) { | |||
} | |||
|
|||
// Glob-style pattern matching. | |||
int StringMatchLen(const char *pattern, int patternLen, const char *string, int stringLen, int nocase) { | |||
int StringMatchLen(const char *pattern, size_t patternLen, const char *string, size_t stringLen, int nocase) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I noticed it via your PR, you can change the camel case to the snake case here for function arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
src/config/config_type.h
Outdated
} | ||
Status Set(const std::string &v) override { | ||
int64_t n; | ||
auto s = Util::DecimalStringToNum(v, &n, min_, max_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use ParseInt<uint32_t>(v, {min_, max_})
here.
src/config/config_type.h
Outdated
std::string ToString() override { return std::to_string(*receiver_); } | ||
Status ToNumber(int64_t *n) override { | ||
*n = *receiver_; | ||
return Status::OK(); | ||
} | ||
Status Set(const std::string &v) override { | ||
int64_t n; | ||
auto s = Util::DecimalStringToNum(v, &n, min_, max_); | ||
auto s = ParseInt(v, {min_, max_}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto s = ParseInt(v, {min_, max_}); | |
auto s = ParseInt<IntegerType>(v, {min_, max_}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be deduced. Is it better to explicitly pass type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to pass type explicitly here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/config/config.cc
Outdated
#ifdef ENABLE_OPENSSL | ||
{"tls-port", true, new IntField(&tls_port, 0, 0, PORT_LIMIT)}, | ||
{"tls-port", true, new IntegerField(&tls_port, (uint32_t)0, (uint32_t)0, PORT_LIMIT)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{"tls-port", true, new IntegerField(&tls_port, (uint32_t)0, (uint32_t)0, PORT_LIMIT)}, | |
{"tls-port", true, new IntegerField<uint32_t>(&tls_port, 0, 0, PORT_LIMIT)}, |
I prefer we specify template types explicitly instead of deduced from arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In all places (and with int
type) or only in few places with types uint32_t
and uint64_t
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can define some aliases, e.g. using IntField = IntergerField<int>
, using UInt32Field = IntergerField<uint32_t>
.
Then you can use these alias in the config map, so most config kv will remain the original form (IntField
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks all, merging... |
Fix #1092