On 22:32 Wed 17 Dec , Marcin Szamotulski wrote: > On 13:07 Wed 17 Dec , Bram Moolenaar wrote: > > > > Marcin Szamotulski wrote: > > > > > On 20:11 Sat 13 Dec , Bram Moolenaar wrote: > > > > > > > > Marcin Szamotulski wrote: > > > > > > > > > I attach the promised patch for checking if the range is invalid. > > > > > > > > Thanks! > > > > > > Updated version, I figured out that 0 range is needed for :tabe. > > > > Thanks. I tried including it, but it breaks tests. > > Also, it would be useful if you can write tests for the boundary checks. > > I see, actually tests fail because one cannot do :888tabnew, which > test62 used, and the tests I wrote were testing that going over the > range will still work for various other commands. I will update the > tests. > > One more question: there is ZEROR flag for the range which some commands > are using. Do you want that the `invalid_range` function tests if the > range is >= 0 or >= 1 depending on the ZEROR flag? > > For example, that would make a difference for the range of :argadd (which can > be 0) > and :argu which does not accept 0. > > Best regards, > Marcin
Here is a patch. I did checked for ZEROR, as this wasn't done before probably by a reason. Best regards, Marcin -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 0c8123c..16e62d0 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -2160,6 +2160,8 @@ do_one_cmd(cmdlinep, sourcing,
break;
case ADDR_ARGUMENTS:
ea.line2 = curwin->w_arg_idx + 1;
+ if (ea.line2 > ARGCOUNT)
+ ea.line2 = ARGCOUNT;
break;
case ADDR_LOADED_BUFFERS:
case ADDR_BUFFERS:
@@ -4572,46 +4574,6 @@ get_address(ptr, addr_type, skip, to_other_file)
lnum -= n;
else
lnum += n;
-
- switch (addr_type)
- {
- case ADDR_LINES:
- break;
- case ADDR_ARGUMENTS:
- if (lnum < 0)
- lnum = 0;
- else if (lnum >= ARGCOUNT)
- lnum = ARGCOUNT;
- break;
- case ADDR_TABS:
- if (lnum < 0)
- {
- lnum = 0;
- break;
- }
- if (lnum >= LAST_TAB_NR)
- lnum = LAST_TAB_NR;
- break;
- case ADDR_WINDOWS:
- if (lnum < 0)
- {
- lnum = 0;
- break;
- }
- if (lnum >= LAST_WIN_NR)
- lnum = LAST_WIN_NR;
- break;
- case ADDR_LOADED_BUFFERS:
- case ADDR_BUFFERS:
- if (lnum < firstbuf->b_fnum)
- {
- lnum = firstbuf->b_fnum;
- break;
- }
- if (lnum > lastbuf->b_fnum)
- lnum = lastbuf->b_fnum;
- break;
- }
}
} while (*cmd == '/' || *cmd == '?');
@@ -4674,17 +4636,65 @@ ex_script_ni(eap)
invalid_range(eap)
exarg_T *eap;
{
+ buf_T *buf;
if ( eap->line1 < 0
|| eap->line2 < 0
- || eap->line1 > eap->line2
- || ((eap->argt & RANGE)
- && !(eap->argt & NOTADR)
- && eap->line2 > curbuf->b_ml.ml_line_count
+ || eap->line1 > eap->line2)
+ return (char_u *)_(e_invrange);
+
+ if (eap->argt & RANGE)
+ {
+ switch(eap->addr_type)
+ {
+ case ADDR_LINES:
+ if (!(eap->argt & NOTADR)
+ && eap->line2 > curbuf->b_ml.ml_line_count
#ifdef FEAT_DIFF
- + (eap->cmdidx == CMD_diffget)
+ + (eap->cmdidx == CMD_diffget)
#endif
- ))
- return (char_u *)_(e_invrange);
+ )
+ return (char_u *)_(e_invrange);
+ break;
+ case ADDR_ARGUMENTS:
+ if (eap->line2 > ARGCOUNT + (!ARGCOUNT)) // add 1 if ARCOUNT is 0
+ return (char_u *)_(e_invrange);
+ break;
+ case ADDR_BUFFERS:
+ if (eap->line1 < firstbuf->b_fnum
+ || eap->line2 > lastbuf->b_fnum)
+ return (char_u *)_(e_invrange);
+ break;
+ case ADDR_LOADED_BUFFERS:
+ buf = firstbuf;
+ while (buf->b_ml.ml_mfp == NULL)
+ {
+ if (buf->b_next == NULL)
+ return (char_u *)_(e_invrange);
+ buf = buf->b_next;
+ }
+ if (eap->line1 < buf->b_fnum)
+ return (char_u *)_(e_invrange);
+ buf = lastbuf;
+ while (buf->b_ml.ml_mfp == NULL)
+ {
+ if (buf->b_prev == NULL)
+ return (char_u *)_(e_invrange);
+ buf = buf->b_prev;
+ }
+ if (eap->line2 > buf->b_fnum)
+ return (char_u *)_(e_invrange);
+ break;
+ case ADDR_WINDOWS:
+ if (eap->line1 < 1
+ || eap->line2 > LAST_WIN_NR)
+ return (char_u *)_(e_invrange);
+ break;
+ case ADDR_TABS:
+ if (eap->line2 > LAST_TAB_NR)
+ return (char_u *)_(e_invrange);
+ break;
+ }
+ }
return NULL;
}
diff --git a/src/testdir/test62.in b/src/testdir/test62.in
index 93d968b..c201fe7 100644
--- a/src/testdir/test62.in
+++ b/src/testdir/test62.in
@@ -13,7 +13,7 @@ STARTTEST
:" Open three tab pages and use ":tabdo"
:0tabnew
:1tabnew
-:888tabnew
+:$tabnew
:tabdo call append(line('$'), 'this is tab page ' . tabpagenr())
:tabclose! 2
:tabrewind
diff --git a/src/testdir/test_argument_count.in b/src/testdir/test_argument_count.in
index cdac030..db7eadb 100644
--- a/src/testdir/test_argument_count.in
+++ b/src/testdir/test_argument_count.in
@@ -27,10 +27,9 @@ STARTTEST
:1arga c
:1arga b
:$argu
-:+arga d
:$arga x
:call add(arglists, argv())
-:$-10arga Y
+:0arga Y
:call add(arglists, argv())
:%argd
:call add(arglists, argv())
diff --git a/src/testdir/test_argument_count.ok b/src/testdir/test_argument_count.ok
index f591bf2..f515626 100644
--- a/src/testdir/test_argument_count.ok
+++ b/src/testdir/test_argument_count.ok
@@ -7,7 +7,7 @@ c
a b d
a d
a
-a b c d x
-Y a b c d x
+a b c x
+Y a b c x
a f
diff --git a/src/testdir/test_close_count.in b/src/testdir/test_close_count.in
index 8a4e090..f07da99 100644
--- a/src/testdir/test_close_count.in
+++ b/src/testdir/test_close_count.in
@@ -28,7 +28,7 @@ STARTTEST
:new
:new
:2wincmd w
-:-2close!
+:-1close!
:let buffers = []
:windo call add(buffers, bufnr('%'))
:call add(tests, buffers)
@@ -61,7 +61,7 @@ STARTTEST
:let buffers = []
:windo call add(buffers, bufnr('%'))
:call add(tests, buffers)
-:9hide
+:$hide
:let buffers = []
:windo call add(buffers, bufnr('%'))
:call add(tests, buffers)
diff --git a/src/testdir/test_command_count.in b/src/testdir/test_command_count.in
index cca178e..7b54cd5 100644
--- a/src/testdir/test_command_count.in
+++ b/src/testdir/test_command_count.in
@@ -42,6 +42,47 @@ STARTTEST
:%RangeTabs
:RangeTabsAll
:1tabonly
+:b1
+ENDTEST
+
+STARTTEST
+:so tiny.vim
+:call add(g:lines, '')
+:%argd
+:arga a b c d
+:let v:errmsg = ''
+:5argu
+:call add(g:lines, '5argu ' . v:errmsg)
+:$argu
+:call add(g:lines, '4argu ' . expand('%:t'))
+:let v:errmsg = ''
+:1argu
+:call add(g:lines, '1argu ' . expand('%:t'))
+:let v:errmsg = ''
+:100b
+:call add(g:lines, '100b ' . v:errmsg)
+:split|split|split|split
+:let v:errmsg = ''
+:0close
+:call add(g:lines, '0close ' . v:errmsg)
+:$wincmd w
+:$close
+:call add(g:lines, '$close ' . winnr())
+:let v:errmsg = ''
+:$+close
+:call add(g:lines, '$+close ' . v:errmsg)
+:$tabe
+:call add(g:lines, '$tabe ' . tabpagenr())
+:let v:errmsg = ''
+:$+tabe
+:call add(g:lines, '$+tabe ' . v:errmsg)
+:only!
+:e x
+:0tabm
+:normal 1gt
+:call add(g:lines, '0tabm ' . expand('%:t'))
+:tabonly!
+:only!
:e! test.out
:call append(0, g:lines)
:w|qa!
diff --git a/src/testdir/test_command_count.ok b/src/testdir/test_command_count.ok
index 11e88b3..92f1012 100644
--- a/src/testdir/test_command_count.ok
+++ b/src/testdir/test_command_count.ok
@@ -15,3 +15,14 @@ RangeTabs 2 5
RangeTabs 1 5
RangeTabsAll 1 5
+5argu E16: Invalid range
+4argu d
+1argu a
+100b E16: Invalid range
+0close E16: Invalid range
+$close 1
+$+close E16: Invalid range
+$tabe 2
+$+tabe E16: Invalid range
+0tabm x
+
signature.asc
Description: Digital signature
