elm_code: better safety around widget edge cases

Fixes crashes when dragging selection out of widget.
@fix
This commit is contained in:
Andy Williams 2017-04-05 22:40:43 +01:00
parent 5da4c96087
commit 650606ab90
2 changed files with 12 additions and 7 deletions

View File

@ -10,7 +10,11 @@ EAPI const char *
elm_code_line_text_get(Elm_Code_Line *line, unsigned int *length)
{
if (!line)
return NULL;
{
if (length)
*length = 0;
return NULL;
}
if (length)
*length = line->length;

View File

@ -653,8 +653,8 @@ _elm_code_widget_position_at_coordinates_get(Eo *obj, Elm_Code_Widget_Data *pd,
Elm_Code_Line *line;
Evas_Coord ox = 0, oy = 0, sx = 0, sy = 0, rowy = 0;
Evas_Object *grid;
int cw = 0, ch = 0, gutter;
unsigned int guess = 0, number;
int cw = 0, ch = 0, gutter, retcol;
unsigned int guess = 1, number;
widget = (Elm_Code_Widget *)obj;
evas_object_geometry_get(widget, &ox, &oy, NULL, NULL);
@ -665,7 +665,7 @@ _elm_code_widget_position_at_coordinates_get(Eo *obj, Elm_Code_Widget_Data *pd,
_elm_code_widget_cell_size_get(widget, &cw, &ch);
gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);
if (ch > 0)
if (y >= 0 && ch > 0)
guess = ((double) y / ch) + 1;
number = guess;
@ -684,10 +684,11 @@ _elm_code_widget_position_at_coordinates_get(Eo *obj, Elm_Code_Widget_Data *pd,
if (col)
{
if (cw == 0)
*col = 0;
retcol = ((double) x / cw) - gutter + 1;
if (retcol <= 0 || cw == 0)
*col = 1;
else
*col = ((double) x / cw) - gutter + 1;
*col = retcol;
}
if (row)
*row = number;