Evas Textblock: Fix NULL dereferencing issue

Summary:
Even if the given two cursor is NULL, it shouldn't be crashed.
@fix

Test Plan:
Test case included in Evas test suite.
Run "make check".

Reviewers: herdsman, tasn

Subscribers: cedric, jpeg

Differential Revision: https://phab.enlightenment.org/D3422
This commit is contained in:
Youngbok Shin 2015-12-13 17:13:13 +02:00 committed by Daniel Hirt
parent 22869bb94e
commit fcba96384f
2 changed files with 15 additions and 7 deletions

View File

@ -9873,9 +9873,6 @@ _evas_textblock_cursor_range_text_markup_get(const Evas_Textblock_Cursor *cur1,
Eina_Strbuf *buf;
Evas_Textblock_Cursor *cur2;
if (!cur1 || !cur1->node) return NULL;
if (!_cur2 || !_cur2->node) return NULL;
if (cur1->obj != _cur2->obj) return NULL;
buf = eina_strbuf_new();
if (evas_textblock_cursor_compare(cur1, _cur2) > 0)
@ -9984,9 +9981,6 @@ _evas_textblock_cursor_range_text_plain_get(const Evas_Textblock_Cursor *cur1, c
Evas_Object_Textblock_Node_Text *n1, *n2;
Evas_Textblock_Cursor *cur2;
if (!cur1 || !cur1->node) return NULL;
if (!_cur2 || !_cur2->node) return NULL;
if (cur1->obj != _cur2->obj) return NULL;
buf = eina_ustrbuf_new();
if (evas_textblock_cursor_compare(cur1, _cur2) > 0)
@ -10111,7 +10105,13 @@ evas_textblock_cursor_range_formats_get(const Evas_Textblock_Cursor *cur1, const
EAPI char *
evas_textblock_cursor_range_text_get(const Evas_Textblock_Cursor *cur1, const Evas_Textblock_Cursor *cur2, Evas_Textblock_Text_Type format)
{
Evas_Object_Protected_Data *obj = eo_data_scope_get(cur1->obj, EVAS_OBJECT_CLASS);
Evas_Object_Protected_Data *obj;
if (!cur1 || !cur1->node) return NULL;
if (!cur2 || !cur2->node) return NULL;
if (cur1->obj != cur2->obj) return NULL;
obj = eo_data_scope_get(cur1->obj, EVAS_OBJECT_CLASS);
evas_object_async_block(obj);
if (format == EVAS_TEXTBLOCK_TEXT_MARKUP)
return _evas_textblock_cursor_range_text_markup_get(cur1, cur2);

View File

@ -2923,6 +2923,14 @@ START_TEST(evas_textblock_text_getters)
"and now in english."));
/* Range get */
/* If one of the given cursor is NULL, it returns NULL. */
fail_if(evas_textblock_cursor_range_text_get(NULL, NULL,
EVAS_TEXTBLOCK_TEXT_MARKUP));
fail_if(evas_textblock_cursor_range_text_get(cur, NULL,
EVAS_TEXTBLOCK_TEXT_MARKUP));
fail_if(evas_textblock_cursor_range_text_get(NULL, cur,
EVAS_TEXTBLOCK_TEXT_MARKUP));
Evas_Textblock_Cursor *main_cur = evas_object_textblock_cursor_get(tb);
evas_textblock_cursor_pos_set(main_cur, 2);
evas_textblock_cursor_pos_set(cur, 2);