Skip to content

Commit

Permalink
feature: limit shift and fractional bits in var edit
Browse files Browse the repository at this point in the history
  • Loading branch information
klonyyy committed Dec 4, 2024
1 parent b803831 commit 209be45
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Gui/GuiVariablesEdit.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _GUI_VARIABLESEDIT_HPP
#define _GUI_VARIABLESEDIT_HPP

#include <algorithm>

#include "GuiHelper.hpp"
#include "Popup.hpp"
#include "Variable.hpp"
Expand Down Expand Up @@ -175,6 +177,7 @@ class VariableEditWindow
if (ImGui::InputText("##shift", &shift, ImGuiInputTextFlags_CharsDecimal, NULL, NULL))
{
uint32_t shiftDec = GuiHelper::convertStringToNumber<uint32_t>(shift);
shiftDec = std::clamp<uint32_t>(shiftDec, 0, (editedVariable->getSize() * 8) - 1);
editedVariable->setShift(shiftDec);
}

Expand Down Expand Up @@ -240,7 +243,8 @@ class VariableEditWindow

if (shouldUpdate)
{
fractional.fractionalBits = GuiHelper::convertStringToNumber<uint32_t>(fractionalBits);
fractional.fractionalBits = std::clamp<uint32_t>(GuiHelper::convertStringToNumber<uint32_t>(fractionalBits), 0, (editedVariable->getSize() * 8) - 1);

if (variableHandler->contains(base))
fractional.baseVariable = variableHandler->getVariable(base).get();
else
Expand Down

0 comments on commit 209be45

Please sign in to comment.