Symbol.cc and FileStream.cc: Fix -Wconversion and -Wuseless-cast on 32-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
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.
Does Avro itself enable -Wuseless-cast or does that come from some surrounding build system?
I doubt that warning will reveal any actual bug, so my first inclination would be to disable it altogether. But I'm not using the Avro C++ library so my opinion shouldn't have much weight here.
Does Avro itself enable
-Wuseless-castor does that come from some surrounding build system?I doubt that warning will reveal any actual bug, so my first inclination would be to disable it altogether. But I'm not using the Avro C++ library so my opinion shouldn't have much weight here.
-Wuseless-cast is enabled by Avro itself in its CMakeLists.txt.
useless-cast warning is gcc specific, if one is using clang then this will be flagged as unknown-warning-option