gulrak / filesystem

An implementation of C++17 std::filesystem for C++11 /C++14/C++17/C++20 on Windows, macOS, Linux and FreeBSD.
MIT License
1.32k stars 168 forks source link

Cast to uintmax_t *before* multiplying in space calculations #133

Closed musicinmybrain closed 2 years ago

musicinmybrain commented 2 years ago

This ensures that all cases where the result actually does fit in a uintmax_t are correctly handled. Before, the multiplication could be performed in a smaller type, leading to an incorrect result or, worse, undefined behavior due to signed integer overflow.

This fixes a test failure that was actually observed on an i686 Linux system.

gulrak commented 2 years ago

You are right, thank you for the fix.