Robustness/fix:
string_next won't advance if the end of string is reached.
This commit is contained in:
1 parent
3dad6ef65c
commit
18f04da4ec
2 files changed
+8
-1
No files matched your search
+3
-1
@@ -1787,8 +1787,10 @@ static inline bool
|
|||||||
m_string_end_p (m_string_it_t it)
|
m_string_end_p (m_string_it_t it)
|
||||||
{
|
{
|
||||||
M_STR1NG_IT_CONTRACT(it);
|
M_STR1NG_IT_CONTRACT(it);
|
||||||
if (M_UNLIKELY (*it->ptr == 0))
|
if (M_UNLIKELY (*it->ptr == 0)) {
|
||||||
|
it->next_ptr = 0; // For safety, don't advance iterator over end of string
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
m_str1ng_utf8_state_e state = M_STR1NG_UTF8_STARTING;
|
m_str1ng_utf8_state_e state = M_STR1NG_UTF8_STARTING;
|
||||||
m_string_unicode_t u = 0;
|
m_string_unicode_t u = 0;
|
||||||
const char *str = it->ptr;
|
const char *str = it->ptr;
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ static void test_utf8_it(void)
|
|||||||
string_init(s);
|
string_init(s);
|
||||||
string_it_end(it2, s);
|
string_it_end(it2, s);
|
||||||
assert( string_it_get_pos(it2) == 0);
|
assert( string_it_get_pos(it2) == 0);
|
||||||
|
string_next(it2);
|
||||||
|
assert( string_it_get_pos(it2) == 0);
|
||||||
|
|
||||||
for(string_it(it, s) ; !string_end_p(it); string_next(it)) {
|
for(string_it(it, s) ; !string_end_p(it); string_next(it)) {
|
||||||
assert(0); // Shall not be called
|
assert(0); // Shall not be called
|
||||||
@@ -106,6 +108,9 @@ static void test_utf8_it(void)
|
|||||||
string_it_pos(it2, s, 0);
|
string_it_pos(it2, s, 0);
|
||||||
assert( !string_end_p(it2) );
|
assert( !string_end_p(it2) );
|
||||||
assert( string_get_cref(it2) == 45);
|
assert( string_get_cref(it2) == 45);
|
||||||
|
string_next(it);
|
||||||
|
assert( string_it_get_pos(it) == 9);
|
||||||
|
assert( string_end_p(it) );
|
||||||
|
|
||||||
string_set_str (s, "H€llo René Chaînôr¬");
|
string_set_str (s, "H€llo René Chaînôr¬");
|
||||||
assert(string_length_u(s) == 19);
|
assert(string_length_u(s) == 19);
|
||||||
|
|||||||
Reference in new issue
Block a user