3433: Symbol.cc and FileStream.cc: Fix -Wconversion and -Wuseless-cast on 32-bit builds#12
3433: Symbol.cc and FileStream.cc: Fix -Wconversion and -Wuseless-cast on 32-bit builds#12martin-augment wants to merge 1 commit intomainfrom
Conversation
…2-bit builds
Symbol.cc:
it - rs.begin() returns a value of type std::ptrdiff_t.
On 32-bit systems, this is typically int, so casting it to int is redundant
and triggers -Wuseless-cast.
FileStream.cc:
size_t is 32-bit on 32-bit systems, while position is int64_t.
Casting int64_t to size_t can lead to truncation, causing -Wconversion errors.
The fix ensures that the offset and position are checked to be non-negative before conversion.
Fix:
lib32-avro-c++/1.12/sources/avro-c++-1.12/lang/c++/impl/parsing/Symbol.cc:91:27:
error: useless cast to type 'int' [-Werror=useless-cast]
91 | adj.push_back(static_cast<int>(it - rs.begin()));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
lib32-avro-c++/1.12/sources/avro-c++-1.12/lang/c++/impl/FileStream.cc:208:41:
error: conversion from 'int64_t' {aka 'long long int'} to 'size_t'
{aka 'unsigned int'} may change value [-Werror=conversion]
208 | in_->seek(position - byteCount_ - available_);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
lib32-avro-c++/1.12/sources/avro-c++-1.12/lang/c++/impl/FileStream.cc:209:22:
error: conversion from 'int64_t' {aka 'long long int'} to 'size_t'
{aka 'unsigned int'} may change value [-Werror=conversion]
209 | byteCount_ = position;
| ^~~~~~~~
cc1plus: all warnings being treated as errors
These changes fix build failures on 32-bit systems and ensure safe type conversions.
Signed-off-by: Alper Ak <alperyasinak1@gmail.com>
| if (offset < 0) { | ||
| throw Exception("Negative offset in seek"); | ||
| } | ||
| in_->seek(static_cast<size_t>(offset)); |
There was a problem hiding this comment.
On 32-bit builds, casting 64-bit offset to size_t can truncate for large values; consider validating that offset fits in size_t before calling in_->seek to avoid incorrect seek.
🤖 React with 👍 or 👎 to let us know if the comment was useful.
There was a problem hiding this comment.
value:useful; category:bug; feedback:prevented an undesired truncation of int64_t to int32_t on 32bit systems.
| if (position < 0) { | ||
| throw Exception("Negative position not allowed"); | ||
| } | ||
| byteCount_ = static_cast<size_t>(position); |
There was a problem hiding this comment.
Similarly, casting position (int64_t) to size_t for byteCount_ can truncate on 32-bit; consider checking the range before assignment. (Related to the cast above.)
🤖 React with 👍 or 👎 to let us know if the comment was useful.
There was a problem hiding this comment.
value:useful; category:bug; feedback:prevented an undesired truncation of int64_t to int32_t on 32bit systems.
| } else { | ||
| adj.push_back(static_cast<int>(it - rs.begin())); | ||
| auto index = it - rs.begin(); | ||
| if constexpr (std::is_same_v<decltype(index), int>) { |
There was a problem hiding this comment.
std::is_same_v requires <type_traits>, but this TU doesn’t include it; consider adding the header to avoid relying on transitive includes and potential build failures.
🤖 React with 👍 or 👎 to let us know if the comment was useful.
There was a problem hiding this comment.
value:useful; category:bug; feedback:It seems <type_traits> is included transitively by some other header file but it is always better to be explicit !
PR Review: Symbol.cc and FileStream.cc - Fix -Wconversion and -Wuseless-cast on 32-bit buildsSummaryThis PR addresses compiler warnings on 32-bit systems by adding proper type conversions and compile-time type checking. The changes target two specific build failures related to Code Quality & Best PracticesFileStream.cc Changes ✅ Generally Good,
|
|
Findings
|
3433: To review by AI