zlacker

[return to "Std: Clamp generates less efficient assembly than std:min(max,std:max(min,v))"]
1. svanta+el[view] [source] 2024-01-16 13:42:56
>>x1f604+(OP)
I'm a heavy std::clamp user, but I'm considering replacing it with min+max because of the uncertainty about what will happen when lo > hi. On windows it triggers an assertion, while other platforms just do a min+max in one or the other order. Of course, this should never happen but can be difficult to guarantee when the limits are derived from user inputs.
◧◩
2. lpapez+cs[view] [source] 2024-01-16 14:30:15
>>svanta+el
> Of course, this should never happen but can be difficult to guarantee when the limits are derived from user inputs.

Sounds to me like you are missing a validation step before calling your logic. When it comes to parsing, trusting user input is a recipe for disaster in the form of buffer overruns and potential exploits.

As they used to say in the Soviet Union: "trust, but verify".

◧◩◪
3. PaulDa+Fu[view] [source] 2024-01-16 14:43:12
>>lpapez+cs
That was what Reagan said about the Soviet Union, not what was said in the Soviet Union.

Correct me if I'm wrong.

◧◩◪◨
4. plucas+0z[view] [source] 2024-01-16 15:05:29
>>PaulDa+Fu
https://en.wikipedia.org/wiki/Trust,_but_verify

> Trust, but verify (Russian: доверяй, но проверяй, tr. doveryay, no proveryay, IPA: [dəvʲɪˈrʲæj no prəvʲɪˈrʲæj]) is a Russian proverb, which is rhyming in Russian. The phrase became internationally known in English after Suzanne Massie, a scholar of Russian history, taught it to Ronald Reagan, then president of the United States, the latter of whom used it on several occasions in the context of nuclear disarmament discussions with the Soviet Union.

Memorably referenced in "Chernobyl": https://youtu.be/9Ebah_QdBnI?t=79

◧◩◪◨⬒
5. dekhn+BP1[view] [source] 2024-01-16 20:46:07
>>plucas+0z
When I hear the phrase, I rewrite it to "don't trust, verify."
[go to top]