Skip to content

Commit 68a191a

Browse files
authored
SimpleString: fix warning by checking upper size limit (#666)
1 parent 1389ae6 commit 68a191a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

include/behaviortree_cpp/utils/simple_string.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class SimpleString {
4949
SimpleString(const char *input_data)
5050
: SimpleString(input_data, strlen(input_data)) {}
5151

52+
5253
SimpleString(const char *input_data, std::size_t size)
5354
{
5455
createImpl(input_data, size);
@@ -132,6 +133,7 @@ class SimpleString {
132133
constexpr static std::size_t CAPACITY = 15; // sizeof(String) - 1);
133134
constexpr static std::size_t IS_LONG_BIT = 1 << 7;
134135
constexpr static std::size_t LONG_MASK = (~std::size_t(0)) >> 1;
136+
constexpr static std::size_t MAX_SIZE = 100UL*1024UL*1024UL;
135137

136138
union {
137139
String str;
@@ -146,6 +148,10 @@ class SimpleString {
146148

147149
void createImpl(const char *input_data, std::size_t size)
148150
{
151+
if (size > MAX_SIZE){
152+
throw std::invalid_argument("size too large for a simple string");
153+
}
154+
149155
if (size > CAPACITY) {
150156
_storage.str.size = size;
151157
_storage.soo.capacity_left = IS_LONG_BIT;

0 commit comments

Comments
 (0)