Skip to content

Commit

Permalink
[apps/graph/values] Fix k_maxNumberOfDisplayableSymbolTypes
Browse files Browse the repository at this point in the history
Fix fuzzer crash:
1. Go to graph
2. Create 1 function of x, 1 of t and 1 of theta
3. Go to values
4. Move 3 times Right and then 2 times Left

Problem was that k_maxNumberOfDisplayableSymbolTypes was 2 but actually
it is 3.
  • Loading branch information
PiaNumworks authored and HugoNumworks committed Apr 11, 2023
1 parent 98b3816 commit b98d69a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion apps/graph/values/values_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <escher/even_odd_editable_text_cell.h>
#include <escher/even_odd_message_text_cell.h>
#include <escher/toggleable_dot_view.h>
#include <omg/round.h>

#include "derivative_parameter_controller.h"
#include "interval_parameter_selector_controller.h"
Expand Down Expand Up @@ -67,7 +68,8 @@ class ValuesController : public Shared::ValuesController,
private:
constexpr static size_t k_maxNumberOfSymbolTypes =
Shared::ContinuousFunctionProperties::k_numberOfSymbolTypes;
constexpr static int k_maxNumberOfDisplayableSymbolTypes = 2;
constexpr static int k_maxNumberOfDisplayableSymbolTypes =
OMG::Ceil(static_cast<float>(k_maxNumberOfDisplayableColumns) / 2.0f);
constexpr static int k_maxNumberOfDisplayableAbscissaCells =
k_maxNumberOfDisplayableSymbolTypes * k_maxNumberOfDisplayableRows;
constexpr static int k_valuesCellBufferSize =
Expand Down
6 changes: 6 additions & 0 deletions omg/include/omg/round.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ static inline T LaxToZero(T x) {
: x;
}

// std::ceil is not constexpr
constexpr int Ceil(float f) {
const int i = static_cast<int>(f);
return f > static_cast<float>(i) ? i + 1 : i;
}

} // namespace OMG

#endif

0 comments on commit b98d69a

Please sign in to comment.