summaryrefslogtreecommitdiff
path: root/src/lib/elementary
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2017-02-18 21:41:53 +0000
committerAndy Williams <andy@andywilliams.me>2017-02-18 21:41:53 +0000
commit2c1aeef3d6f7f035dad2625a7ea06b44eff91deb (patch)
treeb940ca875a0e02802f4edbe076e68c6664562004 /src/lib/elementary
parent4054210990d716377d76d2778b95d08052db2533 (diff)
elm_code: Fix Coverity issues.
@fix CID1356612 CID1368335 CID1368489 CID1371123 CID1371124 CID1371126 CID1371128
Diffstat (limited to 'src/lib/elementary')
-rw-r--r--src/lib/elementary/elm_code_file.c6
-rw-r--r--src/lib/elementary/elm_code_indent.c25
-rw-r--r--src/lib/elementary/elm_code_widget.c19
3 files changed, 32 insertions, 18 deletions
diff --git a/src/lib/elementary/elm_code_file.c b/src/lib/elementary/elm_code_file.c
index 9188050649..ac9626c8eb 100644
--- a/src/lib/elementary/elm_code_file.c
+++ b/src/lib/elementary/elm_code_file.c
@@ -192,8 +192,10 @@ EAPI void elm_code_file_save(Elm_Code_File *file)
192 elm_code_line_text_trailing_whitespace_strip(line_item); 192 elm_code_line_text_trailing_whitespace_strip(line_item);
193 content = elm_code_line_text_get(line_item, &length); 193 content = elm_code_line_text_get(line_item, &length);
194 194
195 fwrite(content, sizeof(char), length, out); 195 if (fwrite(content, sizeof(char), length, out) != length)
196 fwrite(crchars, sizeof(char), crlength, out); 196 break;
197 if (fwrite(crchars, sizeof(char), crlength, out) != crlength)
198 break;
197 } 199 }
198 fclose(out); 200 fclose(out);
199 201
diff --git a/src/lib/elementary/elm_code_indent.c b/src/lib/elementary/elm_code_indent.c
index c76ffb67ec..5002e95077 100644
--- a/src/lib/elementary/elm_code_indent.c
+++ b/src/lib/elementary/elm_code_indent.c
@@ -12,26 +12,29 @@ elm_code_line_indent_startswith_keyword(Elm_Code_Line *line)
12{ 12{
13 regex_t regex; 13 regex_t regex;
14 char *text; 14 char *text;
15 Eina_Bool ret; 15 int ret;
16 unsigned int textlen; 16 unsigned int textlen;
17 17
18 text = (char *)elm_code_line_text_get(line, &textlen); 18 text = (char *)elm_code_line_text_get(line, &textlen);
19 text = strndup(text, textlen); 19 text = strndup(text, textlen);
20 20
21 regcomp(&regex, "^\\s*(" 21 ret = regcomp(&regex, "^\\s*("
22 "((if|else\\s*if|while|for|switch)\\s*\\(.*\\)\\s*\\{?)|" 22 "((if|else\\s*if|while|for|switch)\\s*\\(.*\\)\\s*\\{?)|"
23 "((else|do)\\s*\\{?)|" 23 "((else|do)\\s*\\{?)|"
24 "(case\\s+.+:)|" 24 "(case\\s+.+:)|"
25 "(default:)" 25 "(default:)"
26 ")\\s*$", REG_EXTENDED | REG_NOSUB); 26 ")\\s*$", REG_EXTENDED | REG_NOSUB);
27 if (ret)
28 {
29 regfree(&regex);
30 return EINA_FALSE;
31 }
27 32
28 ret = regexec(&regex, text, 0, NULL, 0); 33 ret = regexec(&regex, text, 0, NULL, 0);
34 regfree(&regex);
29 free(text); 35 free(text);
30 36
31 if (ret == 0) 37 return ret == 0;
32 return EINA_TRUE;
33 else
34 return EINA_FALSE;
35} 38}
36 39
37EAPI char * 40EAPI char *
diff --git a/src/lib/elementary/elm_code_widget.c b/src/lib/elementary/elm_code_widget.c
index 19eb969dc0..06715c75ce 100644
--- a/src/lib/elementary/elm_code_widget.c
+++ b/src/lib/elementary/elm_code_widget.c
@@ -621,7 +621,7 @@ _elm_code_widget_position_at_coordinates_get(Eo *obj, Elm_Code_Widget_Data *pd,
621 Evas_Coord ox = 0, oy = 0, sx = 0, sy = 0, rowy = 0; 621 Evas_Coord ox = 0, oy = 0, sx = 0, sy = 0, rowy = 0;
622 Evas_Object *grid; 622 Evas_Object *grid;
623 int cw = 0, ch = 0, gutter; 623 int cw = 0, ch = 0, gutter;
624 unsigned int guess, number; 624 unsigned int guess = 0, number;
625 625
626 widget = (Elm_Code_Widget *)obj; 626 widget = (Elm_Code_Widget *)obj;
627 evas_object_geometry_get(widget, &ox, &oy, NULL, NULL); 627 evas_object_geometry_get(widget, &ox, &oy, NULL, NULL);
@@ -632,7 +632,8 @@ _elm_code_widget_position_at_coordinates_get(Eo *obj, Elm_Code_Widget_Data *pd,
632 _elm_code_widget_cell_size_get(widget, &cw, &ch); 632 _elm_code_widget_cell_size_get(widget, &cw, &ch);
633 gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); 633 gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);
634 634
635 guess = ((double) y / ch) + 1; 635 if (ch > 0)
636 guess = ((double) y / ch) + 1;
636 number = guess; 637 number = guess;
637 638
638 // unfortunately EINA_LIST_REVERSE_FOREACH skips to the end of the list... 639 // unfortunately EINA_LIST_REVERSE_FOREACH skips to the end of the list...
@@ -649,7 +650,12 @@ _elm_code_widget_position_at_coordinates_get(Eo *obj, Elm_Code_Widget_Data *pd,
649 } 650 }
650 651
651 if (col) 652 if (col)
652 *col = ((double) x / cw) - gutter + 1; 653 {
654 if (cw == 0)
655 *col = 0;
656 else
657 *col = ((double) x / cw) - gutter + 1;
658 }
653 if (row) 659 if (row)
654 *row = number; 660 *row = number;
655 661
@@ -1633,7 +1639,7 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED,
1633 else if (!strcmp(ev->key, "Next")) 1639 else if (!strcmp(ev->key, "Next"))
1634 _elm_code_widget_cursor_move_pagedown(widget); 1640 _elm_code_widget_cursor_move_pagedown(widget);
1635 1641
1636 if (shift) 1642 if (shift && pd->selection)
1637 { 1643 {
1638 if (pd->selection->start_line == pd->selection->end_line) 1644 if (pd->selection->start_line == pd->selection->end_line)
1639 adjust = (pd->selection->end_col > pd->selection->start_col) || 1645 adjust = (pd->selection->end_col > pd->selection->start_col) ||
@@ -1918,7 +1924,8 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline)
1918 ww = w*cw; 1924 ww = w*cw;
1919 if (h*ch > wh) 1925 if (h*ch > wh)
1920 wh = h*ch; 1926 wh = h*ch;
1921 pd->col_count = ww/cw + 1; 1927 if (cw > 0)
1928 pd->col_count = ww/cw + 1;
1922 1929
1923 EINA_LIST_FOREACH(pd->grids, item, grid) 1930 EINA_LIST_FOREACH(pd->grids, item, grid)
1924 { 1931 {
@@ -1962,6 +1969,8 @@ _elm_code_widget_lines_visible_get(Eo *obj, Elm_Code_Widget_Data *pd)
1962 elm_scroller_region_get(pd->scroller, NULL, NULL, NULL, &viewh); 1969 elm_scroller_region_get(pd->scroller, NULL, NULL, NULL, &viewh);
1963 _elm_code_widget_cell_size_get(obj, NULL, &cellh); 1970 _elm_code_widget_cell_size_get(obj, NULL, &cellh);
1964 1971
1972 if (cellh == 0)
1973 return 0;
1965 return viewh / cellh + 1; 1974 return viewh / cellh + 1;
1966} 1975}
1967 1976