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.

[go to top]