Martchus / cpp-utilities

Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities
GNU General Public License v2.0
52 stars 18 forks source link

Fix use of `sendfile()` on 32-bit systems #23

Closed ahesford closed 1 year ago

ahesford commented 1 year ago

std::min(count, bufferSize) fails to compile when bufferSize is a 32-bit unsigned value, at least with GCC 12, because the STL can't find a template for std::min that will compare std::uint64_t to unsigned int. This is fixed by forcing the comparison for 64-bit types, then casting back down to the std::size_t expected by sendfile64. The down-cast can never overflow because the argument is always guaranteed to be no larger than the maximum representable size of the std::size_t bufferSize argument, so this should always be safe.

Martchus commented 1 year ago

Thanks, that makes sense. I haven't catched that before releasing because the only 32-bit target I still build for is mingw-w64.