fix: prevent potential UB using std::clamp.

### Problem description
It is possible for the maximum and minimum value arguments to std::clamp to be swapped which is defined  in the standard as undefined behavior

### Implementation description
Swap the values if necessary.


---------

Co-authored-by: paxcut <53811119+paxcut@users.noreply.github.com>
This commit is contained in:
ThePirate42
2025-05-05 02:24:59 +02:00
committed by GitHub
parent 4883ed0e5a
commit 36eeee5f9c

View File

@@ -335,7 +335,11 @@ namespace hex::plugin::builtin {
auto textEditorSize = availableSize;
textEditorSize.y *= 3.5F / 5.0F;
textEditorSize.y -= ImGui::GetTextLineHeightWithSpacing();
textEditorSize.y = std::clamp(textEditorSize.y + height, 200.0F, availableSize.y - 200.0F);
if (200.0F > availableSize.y - 200.0F) {
textEditorSize.y = std::clamp(textEditorSize.y + height, availableSize.y - 200.0F, 200.0F);
} else {
textEditorSize.y = std::clamp(textEditorSize.y + height, 200.0F, availableSize.y - 200.0F);
}
if (g.NavWindow != nullptr) {
std::string name = g.NavWindow->Name;