comparison src/eval.c @ 21899:8fe86125dcba v8.2.1499

patch 8.2.1499: Vim9: error when using "$" with col() Commit: https://github.com/vim/vim/commit/ec65d77fa26cc87f7ce54a5a941a799e3a667c50 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Aug 20 22:29:12 2020 +0200 patch 8.2.1499: Vim9: error when using "$" with col() Problem: Vim9: error when using "$" with col(). Solution: Reorder getting the column value. (closes https://github.com/vim/vim/issues/6744)
author Bram Moolenaar <Bram@vim.org>
date Thu, 20 Aug 2020 22:30:04 +0200
parents e7e485a60caf
children 2559dc02bd64
comparison
equal deleted inserted replaced
21898:5e70c368bea2 21899:8fe86125dcba
4839 4839
4840 // Get the line number 4840 // Get the line number
4841 pos.lnum = list_find_nr(l, 0L, &error); 4841 pos.lnum = list_find_nr(l, 0L, &error);
4842 if (error || pos.lnum <= 0 || pos.lnum > curbuf->b_ml.ml_line_count) 4842 if (error || pos.lnum <= 0 || pos.lnum > curbuf->b_ml.ml_line_count)
4843 return NULL; // invalid line number 4843 return NULL; // invalid line number
4844 len = (long)STRLEN(ml_get(pos.lnum));
4844 4845
4845 // Get the column number 4846 // Get the column number
4846 pos.col = list_find_nr(l, 1L, &error);
4847 if (error)
4848 return NULL;
4849 len = (long)STRLEN(ml_get(pos.lnum));
4850
4851 // We accept "$" for the column number: last column. 4847 // We accept "$" for the column number: last column.
4852 li = list_find(l, 1L); 4848 li = list_find(l, 1L);
4853 if (li != NULL && li->li_tv.v_type == VAR_STRING 4849 if (li != NULL && li->li_tv.v_type == VAR_STRING
4854 && li->li_tv.vval.v_string != NULL 4850 && li->li_tv.vval.v_string != NULL
4855 && STRCMP(li->li_tv.vval.v_string, "$") == 0) 4851 && STRCMP(li->li_tv.vval.v_string, "$") == 0)
4852 {
4856 pos.col = len + 1; 4853 pos.col = len + 1;
4854 }
4855 else
4856 {
4857 pos.col = list_find_nr(l, 1L, &error);
4858 if (error)
4859 return NULL;
4860 }
4857 4861
4858 // Accept a position up to the NUL after the line. 4862 // Accept a position up to the NUL after the line.
4859 if (pos.col == 0 || (int)pos.col > len + 1) 4863 if (pos.col == 0 || (int)pos.col > len + 1)
4860 return NULL; // invalid column number 4864 return NULL; // invalid column number
4861 --pos.col; 4865 --pos.col;