etl::make_string and etl::make_string_view inconsistent behaviour #424
Replies: 1 comment
-
This was implemented 20.35.0 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It's come to my attention that
etl::make_string
andetl::make_string_view
do not behave in the same way when presented with an array that ends with multiple null terminators such aschar text[10] = { 'H', 'e', 'l', 'l', 'o' };
which results in an array containing
"Hello\0\0\0\0\0"
etl::make_string
will create anetl::string
of capacity 9 containing"Hello"
. The size will be reported as 5.etl::make_string_view
will create anetl::string_view
containing"Hello\0\0\0\0\0"
. The size will be reported as 10.Also, if the array should not contain a terminating null, then
etl::make_string
will search beyond the end of the array, though the resulting string will be within capacity.What I am proposing is to modify the behaviour of both to make them consistent, and fix the buffer overrun issue for
etl::make_string
.Current behaviour
char text[10] = { 'H', 'e', 'l', 'l', 'o' };
etl::make_string(text)
will return an etl::string with a capacity of 9 and size of 5, containing"Hello"
.etl::make_string_view(text)
will return anetl::string_view
of size 10 containing"Hello\0\0\0\0\0"
.char text[6] = { 'H', 'e', 'l', 'l', 'o', '\0' };
etl::make_string(text)
will return anetl::string
with a capacity and size of 5, containing"Hello"
.etl::make_string_view(text)
will return anetl::string_view
of size 5 containing"Hello"
.char text[5] = { 'H', 'e', 'l', 'l', 'o' };
etl::make_string(text)
will return anetl::string
with a capacity and size of 4, containing"Hell"
.etl::make_string_view(text)
will return anetl::string_view
of size 4 containing"Hell"
.Proposed behaviour
char text[10] = { 'H', 'e', 'l', 'l', 'o' };
etl::make_string(text)
will return anetl::string
with a capacity of 9 and size of 5, containing"Hello"
.etl::make_string_view(text)
will return anetl::string_view
of size 5 containing"Hello"
.char text[6] = { 'H', 'e', 'l', 'l', 'o', '\0' };
etl::make_string(text)
will return anetl::string
with a capacity and size of 5, containing"Hello"
.etl::make_string_view(text)
will return anetl::string_view
of size 5 containing"Hello"
.char text[5] = { 'H', 'e', 'l', 'l', 'o' };
etl::make_string(text)
will return anetl::string
with a capacity and size of 5, containing"Hello"
.etl::make_string_view(text)
will return anetl::string_view
of size 4 containing"Hello"
.One change for
etl::make_string
would be thatetl::make_string("Hello World")
would return a string of capacity of 12 rather than 11, although size would still be 11.Beta Was this translation helpful? Give feedback.
All reactions