-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
AVRO-3617: reduce cast warning #1852
base: main
Are you sure you want to change the base?
Conversation
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.
Looks basically good. But there are issues, especially C-style cast.
lang/c++/CMakeLists.txt
Outdated
@@ -64,7 +64,7 @@ if (WIN32 AND NOT CYGWIN AND NOT MSYS) | |||
endif() | |||
|
|||
if (CMAKE_COMPILER_IS_GNUCXX) | |||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror") | |||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wconversion") |
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.
Please make indentation here consistent with the rest of the file.
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.
updated
lang/c++/api/Validator.hh
Outdated
@@ -142,7 +142,7 @@ private: | |||
}; | |||
|
|||
std::vector<CompoundType> compoundStack_; | |||
std::vector<size_t> counters_; | |||
std::vector<int64_t> counters_; |
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 the counters cannot be negative, should this be unit64_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.
updated
memcpy(c, gptr(), toCopy); | ||
c += toCopy; | ||
bytesCopied += toCopy; | ||
gbump(toCopy); | ||
gbump((int) toCopy); |
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 C++ the intent of the cast is made explicit with static_cast
etc. This C style cast make it impossible to find out why is this being cast.
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.
updated
lang/c++/impl/Compiler.cc
Outdated
@@ -384,7 +396,7 @@ static NodePtr makeEnumNode(const Entity &e, | |||
|
|||
static NodePtr makeFixedNode(const Entity &e, | |||
const Name &name, const Object &m) { | |||
int v = static_cast<int>(getLongField(e, m, "size")); | |||
size_t v = getLongField(e, m, "size"); |
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 modern C++ we try to avoid explicitly specifying type in situations like this: please use auto
.
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.
updated
lang/c++/impl/DataFile.cc
Outdated
temp.push_back((checksum >> 16) & 0xFF); | ||
temp.push_back((checksum >> 8) & 0xFF); | ||
temp.push_back(checksum & 0xFF); | ||
temp.push_back((char) ((checksum >> 24) & 0xFF)); |
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.
Again, please use static_cast
.
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.
updated
lang/c++/impl/DataFile.cc
Outdated
@@ -522,18 +522,18 @@ void DataFileReaderBase::sync(int64_t position) { | |||
DataFileSync sync_buffer; | |||
const uint8_t *p = nullptr; | |||
size_t n = 0; | |||
size_t i = 0; | |||
int i = 0; |
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 makes sense to keep i
a size_t
because it is used for indexing and compared against the other size_t
SyncSize
.
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.
updated
lang/c++/impl/Zigzag.cc
Outdated
@@ -30,11 +30,11 @@ encodeInt64(int64_t input, std::array<uint8_t, 10> &output) noexcept { | |||
auto v = val & mask; | |||
size_t bytesOut = 0; | |||
while (val >>= 7) { | |||
output[bytesOut++] = (v | 0x80); | |||
output[bytesOut++] = (uint8_t) (v | 0x80); |
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.
Again, please do static_cast
.
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.
updated
lang/c++/impl/json/JsonIO.cc
Outdated
continue; | ||
} | ||
} | ||
if (n < 0x80) { | ||
result.push_back(n); | ||
result.push_back((char) n); |
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.
static_cast
throughout the file.
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.
updated
lang/c++/test/DataFileTests.cc
Outdated
@@ -473,14 +474,14 @@ class DataFileTest { | |||
avro::DataFileReader<ComplexInteger> df(filename, writerSchema); | |||
std::ifstream just_for_length( | |||
filename, std::ifstream::ate | std::ifstream::binary); | |||
int length = just_for_length.tellg(); | |||
std::streamoff length = just_for_length.tellg(); |
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.
Please use auto
.
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.
updated
All changes done. |
16b7175
to
a816782
Compare
friendly remlinder @thiru-mg, |
a816782
to
374531e
Compare
Try for AVRO-3617