ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/tools/edi.git/commit/?id=ddfd8516357113ab9d041bdc9181b0f433669d17

commit ddfd8516357113ab9d041bdc9181b0f433669d17
Author: Andy Williams <a...@andywilliams.me>
Date:   Sat Aug 29 12:06:30 2015 +0100

    [tests] Correct checking of just length chars
    
    Avoid traversing beyond string length
---
 elm_code/src/tests/elm_code_suite.h                        | 10 ++++++++++
 elm_code/src/tests/widget/elm_code_test_widget_selection.c | 11 +++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/elm_code/src/tests/elm_code_suite.h 
b/elm_code/src/tests/elm_code_suite.h
index 489e8fd..fddba5b 100644
--- a/elm_code/src/tests/elm_code_suite.h
+++ b/elm_code/src/tests/elm_code_suite.h
@@ -3,6 +3,16 @@
 
 #include <check.h>
 
+#define ck_assert_strn_eq(str1, str2, len) \
+  { \
+     unsigned int i = 0; \
+     while (i < len) \
+       { \
+          ck_assert_int_eq(*(str1 + i), *(str2 + i)); \
+          i++; \
+       } \
+  }
+
 #include <Elm_Code.h>
 
 void elm_code_file_test_load(TCase *tc);
diff --git a/elm_code/src/tests/widget/elm_code_test_widget_selection.c 
b/elm_code/src/tests/widget/elm_code_test_widget_selection.c
index bb52747..53d2f11 100644
--- a/elm_code/src/tests/widget/elm_code_test_widget_selection.c
+++ b/elm_code/src/tests/widget/elm_code_test_widget_selection.c
@@ -130,6 +130,7 @@ START_TEST (elm_code_test_widget_selection_delete)
    Elm_Code_Widget *widget;
    Evas_Object *win;
    const char *text;
+   unsigned int length;
 
    elm_init(1, NULL);
    code = elm_code_create();
@@ -139,16 +140,18 @@ START_TEST (elm_code_test_widget_selection_delete)
    win = elm_win_add(NULL, "code", ELM_WIN_BASIC);
    widget = elm_code_widget_add(win, code);
    line = elm_code_file_line_get(file, 1);
-   text = elm_code_line_text_get(line, NULL);
-   ck_assert_str_eq("text", text);
+   text = elm_code_line_text_get(line, &length);
+   ck_assert_int_eq(4, length);
+   ck_assert_strn_eq("text", text, length);
 
    elm_code_widget_selection_start(widget, 1, 2);
    elm_code_widget_selection_end(widget, 1, 3);
    elm_code_widget_selection_delete(widget);
 
    line = elm_code_file_line_get(file, 1);
-   text = elm_code_line_text_get(line, NULL);
-   ck_assert_str_eq("tt", text);
+   text = elm_code_line_text_get(line, &length);
+   ck_assert_int_eq(2, length);
+   ck_assert_strn_eq("tt", text, length);
 
    elm_code_free(code);
    elm_shutdown();

-- 


Reply via email to