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

synstack() bug (and patch)

Expand Messages
  • Matt Wozniski
    Just stumbled across at least one major bug in f_synstack(). We perform the checks on the arguments only after we ve set rettv to be an incompletely
    Message 1 of 2 , Jul 27, 2008
    • 0 Attachment
      Just stumbled across at least one major bug in f_synstack(). We
      perform the checks on the arguments only after we've set rettv to be
      an incompletely initialized list, so it's possible to return something
      useless (and easily crash vim).

      Try, for example, this to see a quick segfault:
      :echo [] + synstack(0,0)

      It seems, looking at other functions, that we should either return an
      empty list in the event of an error in the arguments, or we should
      return 0 and throw an exception. Attached is a patch that fixes this
      by returning an empty list, that will return 0 and print an error
      message if we can't allocate memory for an empty list. This seems to
      be what f_getqflist() does, so hopefully it's an acceptable solution.

      One other thing that I'm not sure I like is that we consider the first
      character of a blank line to be an invalid location (col == 0 not
      strictly less than (long)STRLEN(ml_get(lnum)) == 0). Maybe we should
      allow a column of zero on any valid line, so that we can find out what
      syntax groups are surrounding the cursor? I'm not sure if that makes
      sense or not, but it seems to me that in a C file with just these
      contents:
      <begin>
      /*

      */
      <end>
      and the cursor on the blank line, that synstack(line('.'), col('.'))
      ought to be able to return that we're in a cComment region, even
      though there's no highlighting directly under the cursor... But maybe
      that's not really possible. Any thoughts?

      ~Matt

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Bram Moolenaar
      ... Well, looking at where v_list is defined, it mentions that the value may be NULL. Thus the problem is not where the value is set to NULL, but where it s
      Message 2 of 2 , Jul 27, 2008
      • 0 Attachment
        Matt Wozniski wrote:

        > Just stumbled across at least one major bug in f_synstack(). We
        > perform the checks on the arguments only after we've set rettv to be
        > an incompletely initialized list, so it's possible to return something
        > useless (and easily crash vim).
        >
        > Try, for example, this to see a quick segfault:
        > :echo [] + synstack(0,0)
        >
        > It seems, looking at other functions, that we should either return an
        > empty list in the event of an error in the arguments, or we should
        > return 0 and throw an exception. Attached is a patch that fixes this
        > by returning an empty list, that will return 0 and print an error
        > message if we can't allocate memory for an empty list. This seems to
        > be what f_getqflist() does, so hopefully it's an acceptable solution.

        Well, looking at where v_list is defined, it mentions that the value may
        be NULL. Thus the problem is not where the value is set to NULL, but
        where it's used assuming that it is not NULL. I'll fix that.

        > One other thing that I'm not sure I like is that we consider the first
        > character of a blank line to be an invalid location (col == 0 not
        > strictly less than (long)STRLEN(ml_get(lnum)) == 0). Maybe we should
        > allow a column of zero on any valid line, so that we can find out what
        > syntax groups are surrounding the cursor? I'm not sure if that makes
        > sense or not, but it seems to me that in a C file with just these
        > contents:
        > <begin>
        > /*
        >
        > */
        > <end>
        > and the cursor on the blank line, that synstack(line('.'), col('.'))
        > ought to be able to return that we're in a cComment region, even
        > though there's no highlighting directly under the cursor... But maybe
        > that's not really possible. Any thoughts?

        I don't think that it is possible to get this information without
        changing the syntax HL code.

        --
        [clop clop]
        ARTHUR: Old woman!
        DENNIS: Man!
        ARTHUR: Man, sorry. What knight lives in that castle over there?
        DENNIS: I'm thirty seven.
        ARTHUR: What?
        DENNIS: I'm thirty seven -- I'm not old!
        The Quest for the Holy Grail (Monty Python)

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ download, build and distribute -- http://www.A-A-P.org ///
        \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_dev" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      Your message has been successfully submitted and would be delivered to recipients shortly.