fix: Potential out of bounds access of flightmode name on main screen (#1337)
Take 2, without the Mac Companion breakage... * fixed incorrect use of non-terminated-fixed-string for ctor of std::string * introduced helper * removed commented lines * removed constexpr since in C++11 std::string ctro isn't still constexpr Co-authored-by: wimalopaan <wilhelm.wm.meier@googlemail.com>
This commit is contained in:
co-authored by
wimalopaan
parent
0adb6315c8
commit
121a1ffee5
@@ -328,8 +328,8 @@ void ViewMainDecoration::createFlightMode()
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::function<std::string()> getFM = []() -> std::string {
|
std::function<std::string()> getFM = []() -> std::string {
|
||||||
return g_model.flightModeData[mixerCurrentFlightMode].name;
|
return stringFromNtString(g_model.flightModeData[mixerCurrentFlightMode].name);
|
||||||
};
|
};
|
||||||
|
|
||||||
flightMode = new DynamicText(this, r, getFM, CENTERED | COLOR_THEME_SECONDARY1);
|
flightMode = new DynamicText(this, r, getFM, CENTERED | COLOR_THEME_SECONDARY1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
#include "definitions.h"
|
#include "definitions.h"
|
||||||
#include "opentx_types.h"
|
#include "opentx_types.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#define SHOW_TIME 0x1
|
#define SHOW_TIME 0x1
|
||||||
#define SHOW_TIMER 0x0
|
#define SHOW_TIMER 0x0
|
||||||
#define SHOW_TIMER_UPPER_CASE 0x2
|
#define SHOW_TIMER_UPPER_CASE 0x2
|
||||||
@@ -90,4 +92,8 @@ char *getTimerString(int32_t tme, TimerOptions timerOptions = {.options = 0});
|
|||||||
void splitTimer(char *s0, char *s1, char *s2, char *s3, int tme,
|
void splitTimer(char *s0, char *s1, char *s2, char *s3, int tme,
|
||||||
bool bLowercase = true);
|
bool bLowercase = true);
|
||||||
|
|
||||||
|
template<size_t N>
|
||||||
|
std::string stringFromNtString(const char (&a)[N]) {
|
||||||
|
return std::string(a, strnlen(a, N));
|
||||||
|
}
|
||||||
#endif // _STRHELPERS_H_
|
#endif // _STRHELPERS_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user