To: vim_dev@googlegroups.com Subject: Patch 7.4.1847 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1847 Problem: Getting an item from a NULL dict crashes. Setting a register to a NULL list crashes. (Nikolai Pavlov, issue #768) Comparing a NULL dict with a NULL dict fails. Solution: Properly check for NULL. Files: src/eval.c, src/testdir/test_expr.vim *** ../vim-7.4.1846/src/eval.c 2016-05-25 21:22:56.417828207 +0200 --- src/eval.c 2016-05-25 22:47:35.341758342 +0200 *************** *** 6230,6235 **** --- 6230,6237 ---- dictitem_T *item2; int todo; + if (d1 == NULL && d2 == NULL) + return TRUE; if (d1 == NULL || d2 == NULL) return FALSE; if (d1 == d2) *************** *** 7763,7768 **** --- 7765,7772 ---- char_u *tofree = NULL; hashitem_T *hi; + if (d == NULL) + return NULL; if (len < 0) akey = key; else if (len >= AKEYLEN) *************** *** 18603,18610 **** char_u buf[NUMBUFLEN]; char_u **curval; char_u **curallocval; ! int len = argvars[1].vval.v_list->lv_len; listitem_T *li; /* First half: use for pointers to result lines; second half: use for * pointers to allocated copies. */ --- 18607,18618 ---- char_u buf[NUMBUFLEN]; char_u **curval; char_u **curallocval; ! list_T *ll = argvars[1].vval.v_list; listitem_T *li; + int len; + + /* If the list is NULL handle like an empty list. */ + len = ll == NULL ? 0 : ll->lv_len; /* First half: use for pointers to result lines; second half: use for * pointers to allocated copies. */ *************** *** 18615,18621 **** allocval = lstval + len + 2; curallocval = allocval; ! for (li = argvars[1].vval.v_list->lv_first; li != NULL; li = li->li_next) { strval = get_tv_string_buf_chk(&li->li_tv, buf); --- 18623,18629 ---- allocval = lstval + len + 2; curallocval = allocval; ! for (li = ll == NULL ? NULL : ll->lv_first; li != NULL; li = li->li_next) { strval = get_tv_string_buf_chk(&li->li_tv, buf); *** ../vim-7.4.1846/src/testdir/test_expr.vim 2016-05-24 17:33:29.139206088 +0200 --- src/testdir/test_expr.vim 2016-05-25 22:45:44.377759868 +0200 *************** *** 90,92 **** --- 90,103 ---- call assert_true(0, 'should not get here') endfor endfunc + + func Test_compare_null_dict() + call assert_fails('let x = test_null_dict()[10]') + call assert_equal({}, {}) + call assert_equal(test_null_dict(), test_null_dict()) + call assert_notequal({}, test_null_dict()) + endfunc + + func Test_set_reg_null_list() + call setreg('x', test_null_list()) + endfunc *** ../vim-7.4.1846/src/version.c 2016-05-25 22:00:01.337797601 +0200 --- src/version.c 2016-05-25 22:32:48.185770546 +0200 *************** *** 755,756 **** --- 755,758 ---- { /* Add new patch number below this line */ + /**/ + 1847, /**/ -- hundred-and-one symptoms of being an internet addict: 13. You refer to going to the bathroom as downloading. /// 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 ///