mpusz / wg21-papers

ISO C++ Committee papers by Mateusz Pusz
https://mpusz.github.io/wg21-papers
4 stars 7 forks source link

fix(security): revise or excise note in "7.2 Preventing truncation of data" #50

Closed JohelEGP closed 10 months ago

JohelEGP commented 10 months ago

Please note that it is always assumed that one can convert a quantity into another one with a unit of a higher resolution.

This is not the case: https://godbolt.org/z/nz38764jz. The actual requirement comes from IntegralConversionFactor.

There is no protection against overflow of the representation type. In case the target quantity ends up with a value bigger than the representation type can handle, we will be facing Undefined Behavior.

These aren't universal truths. Maybe they are for int. The first is not the case for a safe number type. The second is not the case for unsigned.

mpusz commented 10 months ago

I tried to fix the note in a few ways, but in the end, I decided to just remove it. We already say that we are compatible with std::chrono::duration and that it might need to be revised. Trying to describe those rules in the text is not needed here.

Thanks for pointing it out!