dendibakh / perf-ninja

This is an online course where you can learn and master the skill of low-level performance analysis and tuning.
2.45k stars 208 forks source link

Fix msvc runtime crash when validating `dep_chains-2` lab #82

Closed jsjtxietian closed 4 months ago

jsjtxietian commented 4 months ago

Hi thanks for the new dep_chains lab !

When compiling the validation exe with msvc and run it, the msvc runtime will complain about invalid min and max arguments for uniform_real, comes from random header when init uniform distribution:

        void _Init(_Ty _Min0, _Ty _Max0) noexcept { // set internal state
            _STL_ASSERT(_Min0 <= _Max0 && (0 <= _Min0 || _Max0 <= _Min0 + (numeric_limits<_Ty>::max)()),
                "invalid min and max arguments for uniform_real");
            _Min = _Min0;
            _Max = _Max0;
        }

Looking closely, I found that the template arg for std::uniform_int_distribution may be wrong and thus the uint32_t's max exceeds int's limit, so MSVC decides to assert it. Clang doesn't have this crash problem but I think it's a bug anyway.

dendibakh commented 4 months ago

Thank you!