Loading ...
Sorry, an error occurred while loading the content.
 

Re: Vim expr parsing bug

Expand Messages
  • Christian Brabandt
    Hi Bram! ... Problem is, in expr1 ? expr2 : expr3 Vim explicitly resets evaluate in the false case which leads to being rettv.v_type being VAR_UNKNOWN and then
    Message 1 of 9 , Nov 22, 2012
      Hi Bram!

      On Do, 22 Nov 2012, Bram Moolenaar wrote:

      >
      > Andy Wokula wrote:
      >
      > > " Vim Parsing Bug
      > >
      > > func! Add2(x1, x2)
      > > return a:x1 + a:x2
      > > endfunc
      > >
      > > :echo function('Add2')(2,3)
      > > " 5 (ok)
      > >
      > > " Bug:
      > > :echo 1 ? function('Add2')(1,2) : function('Add2')(2,3)
      > > :echo 0 ? function('Add2')(1,2) : function('Add2')(2,3)
      > >
      > > " Error detected while processing D1223.vim:
      > > " line 17:
      > > " E110: Missing ')'
      > > " E15: Invalid expression: (2,3)
      > > " line 18:
      > > " E109: Missing ':' after '?'
      > > " E15: Invalid expression: 0 ? function('Add2')(1,2) : function('Add2')(2,3)
      > >
      > >
      > > Adding parentheses 1 ? (...) : (...) doesn't help.
      >
      > Strange. I'll add it to the todo list.

      Problem is, in expr1 ? expr2 : expr3
      Vim explicitly resets evaluate in the false case which leads to being
      rettv.v_type being VAR_UNKNOWN and then handle_subscript doesn't handle
      the subscript anymore.

      Here is a patch:

      diff --git a/src/eval.c b/src/eval.c
      --- a/src/eval.c
      +++ b/src/eval.c
      @@ -19574,7 +19574,7 @@
      while (ret == OK
      && (**arg == '['
      || (**arg == '.' && rettv->v_type == VAR_DICT)
      - || (**arg == '(' && rettv->v_type == VAR_FUNC))
      + || (**arg == '(' && (rettv->v_type == VAR_FUNC || rettv->v_type == VAR_UNKNOWN)))
      && !vim_iswhite(*(*arg - 1)))
      {
      if (**arg == '(')


      regards,
      Christian
      --
      Niemand ist so gut oder so schlecht, wie er während seiner Scheidung
      gemacht wird.
      -- J.J. Disenberg

      --
      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
    • Andy Wokula
      ... Now gVim crashes. -- Andy -- You received this message from the vim_dev maillist. Do not top-post! Type your reply below the text you are replying to.
      Message 2 of 9 , Nov 22, 2012
        Am 22.11.2012 23:28, schrieb Christian Brabandt:
        > Problem is, in expr1 ? expr2 : expr3
        > Vim explicitly resets evaluate in the false case which leads to being
        > rettv.v_type being VAR_UNKNOWN and then handle_subscript doesn't handle
        > the subscript anymore.
        >
        > Here is a patch:
        >
        > diff --git a/src/eval.c b/src/eval.c
        > --- a/src/eval.c
        > +++ b/src/eval.c
        > @@ -19574,7 +19574,7 @@
        > while (ret == OK
        > && (**arg == '['
        > || (**arg == '.' && rettv->v_type == VAR_DICT)
        > - || (**arg == '(' && rettv->v_type == VAR_FUNC))
        > + || (**arg == '(' && (rettv->v_type == VAR_FUNC || rettv->v_type == VAR_UNKNOWN)))
        > && !vim_iswhite(*(*arg - 1)))
        > {
        > if (**arg == '(')

        Now gVim crashes.

        --
        Andy

        --
        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
      • Christian Brabandt
        Hi Andy! ... Hm, interesting. For me it passes all tests. Can you get me a stack trace? regards, Christian -- -- You received this message from the vim_dev
        Message 3 of 9 , Nov 22, 2012
          Hi Andy!

          On Fr, 23 Nov 2012, Andy Wokula wrote:

          > Am 22.11.2012 23:28, schrieb Christian Brabandt:
          > >Problem is, in expr1 ? expr2 : expr3
          > >Vim explicitly resets evaluate in the false case which leads to being
          > >rettv.v_type being VAR_UNKNOWN and then handle_subscript doesn't handle
          > >the subscript anymore.
          > >
          > >Here is a patch:
          > >
          > >diff --git a/src/eval.c b/src/eval.c
          > >--- a/src/eval.c
          > >+++ b/src/eval.c
          > >@@ -19574,7 +19574,7 @@
          > > while (ret == OK
          > > && (**arg == '['
          > > || (**arg == '.' && rettv->v_type == VAR_DICT)
          > >- || (**arg == '(' && rettv->v_type == VAR_FUNC))
          > >+ || (**arg == '(' && (rettv->v_type == VAR_FUNC || rettv->v_type == VAR_UNKNOWN)))
          > > && !vim_iswhite(*(*arg - 1)))
          > > {
          > > if (**arg == '(')
          >
          > Now gVim crashes.

          Hm, interesting. For me it passes all tests. Can you get me a stack
          trace?

          regards,
          Christian
          --

          --
          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
        • Bram Moolenaar
          ... Thanks for the quick fix. Now, how about a test? -- Be thankful to be in a traffic jam, because it means you own a car. /// Bram Moolenaar --
          Message 4 of 9 , Nov 23, 2012
            Christian Brabandt wrote:

            > On Do, 22 Nov 2012, Bram Moolenaar wrote:
            >
            > >
            > > Andy Wokula wrote:
            > >
            > > > " Vim Parsing Bug
            > > >
            > > > func! Add2(x1, x2)
            > > > return a:x1 + a:x2
            > > > endfunc
            > > >
            > > > :echo function('Add2')(2,3)
            > > > " 5 (ok)
            > > >
            > > > " Bug:
            > > > :echo 1 ? function('Add2')(1,2) : function('Add2')(2,3)
            > > > :echo 0 ? function('Add2')(1,2) : function('Add2')(2,3)
            > > >
            > > > " Error detected while processing D1223.vim:
            > > > " line 17:
            > > > " E110: Missing ')'
            > > > " E15: Invalid expression: (2,3)
            > > > " line 18:
            > > > " E109: Missing ':' after '?'
            > > > " E15: Invalid expression: 0 ? function('Add2')(1,2) : function('Add2')(2,3)
            > > >
            > > >
            > > > Adding parentheses 1 ? (...) : (...) doesn't help.
            > >
            > > Strange. I'll add it to the todo list.
            >
            > Problem is, in expr1 ? expr2 : expr3
            > Vim explicitly resets evaluate in the false case which leads to being
            > rettv.v_type being VAR_UNKNOWN and then handle_subscript doesn't handle
            > the subscript anymore.
            >
            > Here is a patch:
            >
            > diff --git a/src/eval.c b/src/eval.c
            > --- a/src/eval.c
            > +++ b/src/eval.c
            > @@ -19574,7 +19574,7 @@
            > while (ret == OK
            > && (**arg == '['
            > || (**arg == '.' && rettv->v_type == VAR_DICT)
            > - || (**arg == '(' && rettv->v_type == VAR_FUNC))
            > + || (**arg == '(' && (rettv->v_type == VAR_FUNC || rettv->v_type == VAR_UNKNOWN)))
            > && !vim_iswhite(*(*arg - 1)))
            > {
            > if (**arg == '(')

            Thanks for the quick fix.

            Now, how about a test?

            --
            Be thankful to be in a traffic jam, because it means you own a car.

            /// Bram Moolenaar -- Bram@... -- 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 ///

            --
            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
          • Christian Brabandt
            Hi Bram! ... Well, I am not sure, what caused the segfault for Andy. But I have been checking with him privately, that this patch works and added some tests.
            Message 5 of 9 , Nov 23, 2012
              Hi Bram!

              On Fr, 23 Nov 2012, Bram Moolenaar wrote:

              >
              > Christian Brabandt wrote:
              >
              > > On Do, 22 Nov 2012, Bram Moolenaar wrote:
              > >
              > > >
              > > > Andy Wokula wrote:
              > > >
              > > > > " Vim Parsing Bug
              > > > >
              > > > > func! Add2(x1, x2)
              > > > > return a:x1 + a:x2
              > > > > endfunc
              > > > >
              > > > > :echo function('Add2')(2,3)
              > > > > " 5 (ok)
              > > > >
              > > > > " Bug:
              > > > > :echo 1 ? function('Add2')(1,2) : function('Add2')(2,3)
              > > > > :echo 0 ? function('Add2')(1,2) : function('Add2')(2,3)
              > > > >
              > > > > " Error detected while processing D1223.vim:
              > > > > " line 17:
              > > > > " E110: Missing ')'
              > > > > " E15: Invalid expression: (2,3)
              > > > > " line 18:
              > > > > " E109: Missing ':' after '?'
              > > > > " E15: Invalid expression: 0 ? function('Add2')(1,2) : function('Add2')(2,3)
              > > > >
              > > > >
              > > > > Adding parentheses 1 ? (...) : (...) doesn't help.
              > > >
              > > > Strange. I'll add it to the todo list.
              > >
              > > Problem is, in expr1 ? expr2 : expr3
              > > Vim explicitly resets evaluate in the false case which leads to being
              > > rettv.v_type being VAR_UNKNOWN and then handle_subscript doesn't handle
              > > the subscript anymore.
              > >
              > > Here is a patch:
              > >
              > > diff --git a/src/eval.c b/src/eval.c
              > > --- a/src/eval.c
              > > +++ b/src/eval.c
              > > @@ -19574,7 +19574,7 @@
              > > while (ret == OK
              > > && (**arg == '['
              > > || (**arg == '.' && rettv->v_type == VAR_DICT)
              > > - || (**arg == '(' && rettv->v_type == VAR_FUNC))
              > > + || (**arg == '(' && (rettv->v_type == VAR_FUNC || rettv->v_type == VAR_UNKNOWN)))
              > > && !vim_iswhite(*(*arg - 1)))
              > > {
              > > if (**arg == '(')
              >
              > Thanks for the quick fix.
              >
              > Now, how about a test?

              Well, I am not sure, what caused the segfault for Andy. But I have been
              checking with him privately, that this patch works and added some tests.
              So here we go, a different patch, including a test.

              regards,
              Christian
              --

              --
              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
            • Bram Moolenaar
              ... Thanks! -- hundred-and-one symptoms of being an internet addict: 62. If your doorbell rings, you think that new mail has arrived. And then you re
              Message 6 of 9 , Nov 23, 2012
                Christian Brabandt wrote:

                > On Fr, 23 Nov 2012, Bram Moolenaar wrote:
                >
                > > Christian Brabandt wrote:
                > >
                > > > On Do, 22 Nov 2012, Bram Moolenaar wrote:
                > > >
                > > > >
                > > > > Andy Wokula wrote:
                > > > >
                > > > > > " Vim Parsing Bug
                > > > > >
                > > > > > func! Add2(x1, x2)
                > > > > > return a:x1 + a:x2
                > > > > > endfunc
                > > > > >
                > > > > > :echo function('Add2')(2,3)
                > > > > > " 5 (ok)
                > > > > >
                > > > > > " Bug:
                > > > > > :echo 1 ? function('Add2')(1,2) : function('Add2')(2,3)
                > > > > > :echo 0 ? function('Add2')(1,2) : function('Add2')(2,3)
                > > > > >
                > > > > > " Error detected while processing D1223.vim:
                > > > > > " line 17:
                > > > > > " E110: Missing ')'
                > > > > > " E15: Invalid expression: (2,3)
                > > > > > " line 18:
                > > > > > " E109: Missing ':' after '?'
                > > > > > " E15: Invalid expression: 0 ? function('Add2')(1,2) : function('Add2')(2,3)
                > > > > >
                > > > > >
                > > > > > Adding parentheses 1 ? (...) : (...) doesn't help.
                > > > >
                > > > > Strange. I'll add it to the todo list.
                > > >
                > > > Problem is, in expr1 ? expr2 : expr3
                > > > Vim explicitly resets evaluate in the false case which leads to being
                > > > rettv.v_type being VAR_UNKNOWN and then handle_subscript doesn't handle
                > > > the subscript anymore.
                > > >
                > > > Here is a patch:
                > > >
                > > > diff --git a/src/eval.c b/src/eval.c
                > > > --- a/src/eval.c
                > > > +++ b/src/eval.c
                > > > @@ -19574,7 +19574,7 @@
                > > > while (ret == OK
                > > > && (**arg == '['
                > > > || (**arg == '.' && rettv->v_type == VAR_DICT)
                > > > - || (**arg == '(' && rettv->v_type == VAR_FUNC))
                > > > + || (**arg == '(' && (rettv->v_type == VAR_FUNC || rettv->v_type == VAR_UNKNOWN)))
                > > > && !vim_iswhite(*(*arg - 1)))
                > > > {
                > > > if (**arg == '(')
                > >
                > > Thanks for the quick fix.
                > >
                > > Now, how about a test?
                >
                > Well, I am not sure, what caused the segfault for Andy. But I have been
                > checking with him privately, that this patch works and added some tests.
                > So here we go, a different patch, including a test.

                Thanks!

                --
                hundred-and-one symptoms of being an internet addict:
                62. If your doorbell rings, you think that new mail has arrived. And then
                you're disappointed that it's only someone at the door.

                /// Bram Moolenaar -- Bram@... -- 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 ///

                --
                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
              • Andy Wokula
                ... (obsolete patch) ... So far, this latest patch works ok for me. -- Andy -- You received this message from the vim_dev maillist. Do not top-post! Type
                Message 7 of 9 , Jan 4, 2013
                  Am 23.11.2012 22:09, schrieb Bram Moolenaar:
                  >
                  > Christian Brabandt wrote:
                  >
                  >> On Fr, 23 Nov 2012, Bram Moolenaar wrote:
                  >>
                  >>> Christian Brabandt wrote:
                  >>>
                  >>>> On Do, 22 Nov 2012, Bram Moolenaar wrote:
                  >>>>
                  >>>>>
                  >>>>> Andy Wokula wrote:
                  >>>>>
                  >>>>>> " Vim Parsing Bug
                  >>>>>>
                  >>>>>> func! Add2(x1, x2)
                  >>>>>> return a:x1 + a:x2
                  >>>>>> endfunc
                  >>>>>>
                  >>>>>> :echo function('Add2')(2,3)
                  >>>>>> " 5 (ok)
                  >>>>>>
                  >>>>>> " Bug:
                  >>>>>> :echo 1 ? function('Add2')(1,2) : function('Add2')(2,3)
                  >>>>>> :echo 0 ? function('Add2')(1,2) : function('Add2')(2,3)
                  >>>>>>
                  >>>>>> " Error detected while processing D1223.vim:
                  >>>>>> " line 17:
                  >>>>>> " E110: Missing ')'
                  >>>>>> " E15: Invalid expression: (2,3)
                  >>>>>> " line 18:
                  >>>>>> " E109: Missing ':' after '?'
                  >>>>>> " E15: Invalid expression: 0 ? function('Add2')(1,2) : function('Add2')(2,3)
                  >>>>>>
                  >>>>>>
                  >>>>>> Adding parentheses 1 ? (...) : (...) doesn't help.
                  >>>>>
                  >>>>> Strange. I'll add it to the todo list.
                  >>>>
                  >>>> Problem is, in expr1 ? expr2 : expr3
                  >>>> Vim explicitly resets evaluate in the false case which leads to being
                  >>>> rettv.v_type being VAR_UNKNOWN and then handle_subscript doesn't handle
                  >>>> the subscript anymore.
                  >>>>
                  >>>> Here is a patch:
                  (obsolete patch)
                  >>>
                  >>> Thanks for the quick fix.
                  >>>
                  >>> Now, how about a test?
                  >>
                  >> Well, I am not sure, what caused the segfault for Andy. But I have been
                  >> checking with him privately, that this patch works and added some tests.
                  >> So here we go, a different patch, including a test.
                  >
                  > Thanks!

                  So far, this latest patch works ok for me.

                  --
                  Andy

                  --
                  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
                Your message has been successfully submitted and would be delivered to recipients shortly.