To: vim_dev@googlegroups.com Subject: Patch 7.4.2068 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.2068 Problem: Not all arguments of trunc_string() are tested. Memory access error when running the message tests. Solution: Add another test case. (Yegappan Lakshmanan) Make it easy to run unittests with valgrind. Fix the access error. Files: src/message.c, src/testdir/message_test.c, src/Makefile *** ../vim-7.4.2067/src/message.c 2016-07-16 19:49:54.372304144 +0200 --- src/message.c 2016-07-19 12:15:01.029275477 +0200 *************** *** 298,306 **** { do half = half - (*mb_head_off)(s, s + half - 1) - 1; ! while (utf_iscomposing(utf_ptr2char(s + half)) && half > 0); n = ptr2cells(s + half); ! if (len + n > room) break; len += n; i = half; --- 298,306 ---- { do half = half - (*mb_head_off)(s, s + half - 1) - 1; ! while (half > 0 && utf_iscomposing(utf_ptr2char(s + half))); n = ptr2cells(s + half); ! if (len + n > room || half == 0) break; len += n; i = half; *** ../vim-7.4.2067/src/message_test.c 2016-07-16 19:49:54.372304144 +0200 --- src/message_test.c 2016-07-18 23:37:33.526184994 +0200 *************** *** 28,64 **** static void test_trunc_string(void) { ! char_u buf[40]; /* in place */ STRCPY(buf, "text"); trunc_string(buf, buf, 20, 40); assert(STRCMP(buf, "text") == 0); STRCPY(buf, "a short text"); trunc_string(buf, buf, 20, 40); assert(STRCMP(buf, "a short text") == 0); STRCPY(buf, "a text tha just fits"); trunc_string(buf, buf, 20, 40); assert(STRCMP(buf, "a text tha just fits") == 0); STRCPY(buf, "a text that nott fits"); trunc_string(buf, buf, 20, 40); assert(STRCMP(buf, "a text t...nott fits") == 0); /* copy from string to buf */ ! trunc_string((char_u *)"text", buf, 20, 40); assert(STRCMP(buf, "text") == 0); ! trunc_string((char_u *)"a short text", buf, 20, 40); assert(STRCMP(buf, "a short text") == 0); ! trunc_string((char_u *)"a text tha just fits", buf, 20, 40); assert(STRCMP(buf, "a text tha just fits") == 0); ! trunc_string((char_u *)"a text that nott fits", buf, 20, 40); assert(STRCMP(buf, "a text t...nott fits") == 0); } int --- 28,96 ---- static void test_trunc_string(void) { ! char_u *buf; /*allocated every time to find uninit errors */ ! char_u *s; /* in place */ + buf = alloc(40); STRCPY(buf, "text"); trunc_string(buf, buf, 20, 40); assert(STRCMP(buf, "text") == 0); + vim_free(buf); + buf = alloc(40); STRCPY(buf, "a short text"); trunc_string(buf, buf, 20, 40); assert(STRCMP(buf, "a short text") == 0); + vim_free(buf); + buf = alloc(40); STRCPY(buf, "a text tha just fits"); trunc_string(buf, buf, 20, 40); assert(STRCMP(buf, "a text tha just fits") == 0); + vim_free(buf); + buf = alloc(40); STRCPY(buf, "a text that nott fits"); trunc_string(buf, buf, 20, 40); assert(STRCMP(buf, "a text t...nott fits") == 0); + vim_free(buf); /* copy from string to buf */ ! buf = alloc(40); ! s = vim_strsave((char_u *)"text"); ! trunc_string(s, buf, 20, 40); assert(STRCMP(buf, "text") == 0); + vim_free(buf); + vim_free(s); ! buf = alloc(40); ! s = vim_strsave((char_u *)"a text that fits"); ! trunc_string(s, buf, 34, 40); ! assert(STRCMP(buf, "a text that fits") == 0); ! vim_free(buf); ! vim_free(s); ! ! buf = alloc(40); ! s = vim_strsave((char_u *)"a short text"); ! trunc_string(s, buf, 20, 40); assert(STRCMP(buf, "a short text") == 0); + vim_free(buf); + vim_free(s); ! buf = alloc(40); ! s = vim_strsave((char_u *)"a text tha just fits"); ! trunc_string(s, buf, 20, 40); assert(STRCMP(buf, "a text tha just fits") == 0); + vim_free(buf); + vim_free(s); ! buf = alloc(40); ! s = vim_strsave((char_u *)"a text that nott fits"); ! trunc_string(s, buf, 20, 40); assert(STRCMP(buf, "a text t...nott fits") == 0); + vim_free(buf); + vim_free(s); } int *** ../vim-7.4.2067/src/Makefile 2016-07-17 22:13:26.817095253 +0200 --- src/Makefile 2016-07-18 23:24:51.062074783 +0200 *************** *** 602,607 **** --- 602,611 ---- # PURIFY - remove the # to use the "purify" program (hoi Nia++!) #PURIFY = purify + # VALGRIND - remove the # to use valgrind for memory leaks and access errors. + # Used for the unittest targets. + # VALGRIND = valgrind --tool=memcheck --leak-check=yes --num-callers=25 --log-file=valgrind.$@ + # NBDEBUG - debugging the netbeans interface. #EXTRA_DEFS = -DNBDEBUG *************** *** 1567,1572 **** --- 1571,1577 ---- UNITTEST_SRC = $(JSON_TEST_SRC) $(MEMFILE_TEST_SRC) $(MESSAGE_TEST_SRC) UNITTEST_TARGETS = $(JSON_TEST_TARGET) $(MEMFILE_TEST_TARGET) $(MESSAGE_TEST_TARGET) + RUN_UNITTESTS = run_json_test run_memfile_test run_message_test # All sources, also the ones that are not configured ALL_SRC = $(BASIC_SRC) $(ALL_GUI_SRC) $(UNITTEST_SRC) $(EXTRA_SRC) *************** *** 1987,2005 **** $(MAKE) -f Makefile $(UNITTEST_TARGETS) # Execute the unittests one by one. ! unittest unittests: $(UNITTEST_TARGETS) ! @for t in $(UNITTEST_TARGETS); do \ ! ./$$t || exit 1; echo $$t passed; \ ! done run_json_test: $(JSON_TEST_TARGET) ! ./$(JSON_TEST_TARGET) run_memfile_test: $(MEMFILE_TEST_TARGET) ! ./$(MEMFILE_TEST_TARGET) run_message_test: $(MESSAGE_TEST_TARGET) ! ./$(MESSAGE_TEST_TARGET) # Run individual OLD style test, assuming that Vim was already compiled. test1 \ --- 1992,2007 ---- $(MAKE) -f Makefile $(UNITTEST_TARGETS) # Execute the unittests one by one. ! unittest unittests: $(RUN_UNITTESTS) run_json_test: $(JSON_TEST_TARGET) ! $(VALGRIND) ./$(JSON_TEST_TARGET) || exit 1; echo $* passed; run_memfile_test: $(MEMFILE_TEST_TARGET) ! $(VALGRIND) ./$(MEMFILE_TEST_TARGET) || exit 1; echo $* passed; run_message_test: $(MESSAGE_TEST_TARGET) ! $(VALGRIND) ./$(MESSAGE_TEST_TARGET) || exit 1; echo $* passed; # Run individual OLD style test, assuming that Vim was already compiled. test1 \ *** ../vim-7.4.2067/src/version.c 2016-07-18 22:22:34.984686583 +0200 --- src/version.c 2016-07-19 12:20:39.801864219 +0200 *************** *** 760,761 **** --- 760,763 ---- { /* Add new patch number below this line */ + /**/ + 2068, /**/ -- Shit makes the flowers grow and that's beautiful /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///