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

About patch 7.1.130

Expand Messages
  • Bram Moolenaar
    Patch 7.1.130 Problem: Crash with specific order of undo and redo. (A.Politz) Solution: Clear and adjust pointers properly. Add u_check() for debugging.
    Message 1 of 7 , Oct 1, 2007
      Patch 7.1.130
      Problem: Crash with specific order of undo and redo. (A.Politz)
      Solution: Clear and adjust pointers properly. Add u_check() for debugging.
      Files: src/undo.c, src/structs.h


      *** ../vim-7.1.129/src/undo.c Thu May 10 20:01:43 2007
      --- src/undo.c Mon Oct 1 22:49:16 2007
      ***************
      *** 76,81 ****
      --- 76,87 ----
      * buffer is unloaded.
      */

      + /* Uncomment the next line for including the u_check() function. This warns
      + * for errors in the debug information. */
      + /* #define U_DEBUG 1 */
      + #define UH_MAGIC 0x18dade /* value for uh_magic when in use */
      + #define UE_MAGIC 0xabc123 /* value for ue_magic when in use */
      +
      #include "vim.h"

      /* See below: use malloc()/free() for memory management. */
      ***************
      *** 113,118 ****
      --- 119,213 ----
      */
      static int undo_undoes = FALSE;

      + #ifdef U_DEBUG
      + /*
      + * Check the undo structures for being valid. Print a warning when something
      + * looks wrong.
      + */
      + static int seen_b_u_curhead;
      + static int seen_b_u_newhead;
      + static int header_count;
      +
      + static void
      + u_check_tree(u_header_T *uhp,
      + u_header_T *exp_uh_next,
      + u_header_T *exp_uh_alt_prev)
      + {
      + u_entry_T *uep;
      +
      + if (uhp == NULL)
      + return;
      + ++header_count;
      + if (uhp == curbuf->b_u_curhead && ++seen_b_u_curhead > 1)
      + {
      + EMSG("b_u_curhead found twice (looping?)");
      + return;
      + }
      + if (uhp == curbuf->b_u_newhead && ++seen_b_u_newhead > 1)
      + {
      + EMSG("b_u_newhead found twice (looping?)");
      + return;
      + }
      +
      + if (uhp->uh_magic != UH_MAGIC)
      + EMSG("uh_magic wrong (may be using freed memory)");
      + else
      + {
      + /* Check pointers back are correct. */
      + if (uhp->uh_next != exp_uh_next)
      + {
      + EMSG("uh_next wrong");
      + smsg((char_u *)"expected: 0x%x, actual: 0x%x",
      + exp_uh_next, uhp->uh_next);
      + }
      + if (uhp->uh_alt_prev != exp_uh_alt_prev)
      + {
      + EMSG("uh_alt_prev wrong");
      + smsg((char_u *)"expected: 0x%x, actual: 0x%x",
      + exp_uh_alt_prev, uhp->uh_alt_prev);
      + }
      +
      + /* Check the undo tree at this header. */
      + for (uep = uhp->uh_entry; uep != NULL; uep = uep->ue_next)
      + {
      + if (uep->ue_magic != UE_MAGIC)
      + {
      + EMSG("ue_magic wrong (may be using freed memory)");
      + break;
      + }
      + }
      +
      + /* Check the next alt tree. */
      + u_check_tree(uhp->uh_alt_next, uhp->uh_next, uhp);
      +
      + /* Check the next header in this branch. */
      + u_check_tree(uhp->uh_prev, uhp, NULL);
      + }
      + }
      +
      + void
      + u_check(int newhead_may_be_NULL)
      + {
      + seen_b_u_newhead = 0;
      + seen_b_u_curhead = 0;
      + header_count = 0;
      +
      + u_check_tree(curbuf->b_u_oldhead, NULL, NULL);
      +
      + if (seen_b_u_newhead == 0 && curbuf->b_u_oldhead != NULL
      + && !(newhead_may_be_NULL && curbuf->b_u_newhead == NULL))
      + EMSGN("b_u_newhead invalid: 0x%x", curbuf->b_u_newhead);
      + if (curbuf->b_u_curhead != NULL && seen_b_u_curhead == 0)
      + EMSGN("b_u_curhead invalid: 0x%x", curbuf->b_u_curhead);
      + if (header_count != curbuf->b_u_numhead)
      + {
      + EMSG("b_u_numhead invalid");
      + smsg((char_u *)"expected: %ld, actual: %ld",
      + (long)header_count, (long)curbuf->b_u_numhead);
      + }
      + }
      + #endif
      +
      /*
      * Save the current line for both the "u" and "U" command.
      * Returns OK or FAIL.
      ***************
      *** 243,248 ****
      --- 338,346 ----
      if (!undo_allowed())
      return FAIL;

      + #ifdef U_DEBUG
      + u_check(FALSE);
      + #endif
      #ifdef FEAT_NETBEANS_INTG
      /*
      * Netbeans defines areas that cannot be modified. Bail out here when
      ***************
      *** 294,299 ****
      --- 392,400 ----
      uhp = (u_header_T *)U_ALLOC_LINE((unsigned)sizeof(u_header_T));
      if (uhp == NULL)
      goto nomem;
      + #ifdef U_DEBUG
      + uhp->uh_magic = UH_MAGIC;
      + #endif
      }
      else
      uhp = NULL;
      ***************
      *** 316,323 ****
      {
      u_header_T *uhfree = curbuf->b_u_oldhead;

      ! /* If there is no branch only free one header. */
      ! if (uhfree->uh_alt_next == NULL)
      u_freeheader(curbuf, uhfree, &old_curhead);
      else
      {
      --- 417,427 ----
      {
      u_header_T *uhfree = curbuf->b_u_oldhead;

      ! if (uhfree == old_curhead)
      ! /* Can't reconnect the branch, delete all of it. */
      ! u_freebranch(curbuf, uhfree, &old_curhead);
      ! else if (uhfree->uh_alt_next == NULL)
      ! /* There is no branch, only free one header. */
      u_freeheader(curbuf, uhfree, &old_curhead);
      else
      {
      ***************
      *** 326,331 ****
      --- 430,438 ----
      uhfree = uhfree->uh_alt_next;
      u_freebranch(curbuf, uhfree, &old_curhead);
      }
      + #ifdef U_DEBUG
      + u_check(TRUE);
      + #endif
      }

      if (uhp == NULL) /* no undo at all */
      ***************
      *** 478,483 ****
      --- 585,593 ----
      uep = (u_entry_T *)U_ALLOC_LINE((unsigned)sizeof(u_entry_T));
      if (uep == NULL)
      goto nomem;
      + #ifdef U_DEBUG
      + uep->ue_magic = UE_MAGIC;
      + #endif

      uep->ue_size = size;
      uep->ue_top = top;
      ***************
      *** 525,530 ****
      --- 635,643 ----
      curbuf->b_u_synced = FALSE;
      undo_undoes = FALSE;

      + #ifdef U_DEBUG
      + u_check(FALSE);
      + #endif
      return OK;

      nomem:
      ***************
      *** 955,960 ****
      --- 1068,1076 ----
      int empty_buffer; /* buffer became empty */
      u_header_T *curhead = curbuf->b_u_curhead;

      + #ifdef U_DEBUG
      + u_check(FALSE);
      + #endif
      old_flags = curhead->uh_flags;
      new_flags = (curbuf->b_changed ? UH_CHANGED : 0) +
      ((curbuf->b_ml.ml_flags & ML_EMPTY) ? UH_EMPTYBUF : 0);
      ***************
      *** 1186,1191 ****
      --- 1302,1310 ----
      /* The timestamp can be the same for multiple changes, just use the one of
      * the undone/redone change. */
      curbuf->b_u_seq_time = curhead->uh_time;
      + #ifdef U_DEBUG
      + u_check(FALSE);
      + #endif
      }

      /*
      ***************
      *** 1515,1521 ****
      }

      /*
      ! * Free one header and its entry list and adjust the pointers.
      */
      static void
      u_freeheader(buf, uhp, uhpp)
      --- 1634,1640 ----
      }

      /*
      ! * Free one header "uhp" and its entry list and adjust the pointers.
      */
      static void
      u_freeheader(buf, uhp, uhpp)
      ***************
      *** 1523,1528 ****
      --- 1642,1649 ----
      u_header_T *uhp;
      u_header_T **uhpp; /* if not NULL reset when freeing this header */
      {
      + u_header_T *uhap;
      +
      /* When there is an alternate redo list free that branch completely,
      * because we can never go there. */
      if (uhp->uh_alt_next != NULL)
      ***************
      *** 1540,1546 ****
      if (uhp->uh_prev == NULL)
      buf->b_u_newhead = uhp->uh_next;
      else
      ! uhp->uh_prev->uh_next = uhp->uh_next;

      u_freeentries(buf, uhp, uhpp);
      }
      --- 1661,1668 ----
      if (uhp->uh_prev == NULL)
      buf->b_u_newhead = uhp->uh_next;
      else
      ! for (uhap = uhp->uh_prev; uhap != NULL; uhap = uhap->uh_alt_next)
      ! uhap->uh_next = uhp->uh_next;

      u_freeentries(buf, uhp, uhpp);
      }
      ***************
      *** 1585,1590 ****
      --- 1707,1714 ----
      /* Check for pointers to the header that become invalid now. */
      if (buf->b_u_curhead == uhp)
      buf->b_u_curhead = NULL;
      + if (buf->b_u_newhead == uhp)
      + buf->b_u_newhead = NULL; /* freeing the newest entry */
      if (uhpp != NULL && uhp == *uhpp)
      *uhpp = NULL;

      ***************
      *** 1594,1599 ****
      --- 1718,1726 ----
      u_freeentry(uep, uep->ue_size);
      }

      + #ifdef U_DEBUG
      + uhp->uh_magic = 0;
      + #endif
      U_FREE_LINE((char_u *)uhp);
      --buf->b_u_numhead;
      }
      ***************
      *** 1609,1614 ****
      --- 1736,1744 ----
      while (n > 0)
      U_FREE_LINE(uep->ue_array[--n]);
      U_FREE_LINE((char_u *)uep->ue_array);
      + #ifdef U_DEBUG
      + uep->ue_magic = 0;
      + #endif
      U_FREE_LINE((char_u *)uep);
      }

      *** ../vim-7.1.129/src/structs.h Sun Aug 12 15:50:26 2007
      --- src/structs.h Sat Sep 29 15:03:38 2007
      ***************
      *** 278,283 ****
      --- 278,286 ----
      linenr_T ue_lcount; /* linecount when u_save called */
      char_u **ue_array; /* array of lines in undo block */
      long ue_size; /* number of lines in ue_array */
      + #ifdef U_DEBUG
      + int ue_magic; /* magic number to check allocation */
      + #endif
      };

      struct u_header
      ***************
      *** 300,305 ****
      --- 303,311 ----
      visualinfo_T uh_visual; /* Visual areas before undo/after redo */
      #endif
      time_t uh_time; /* timestamp when the change was made */
      + #ifdef U_DEBUG
      + int uh_magic; /* magic number to check allocation */
      + #endif
      };

      /* values for uh_flags */
      *** ../vim-7.1.129/src/version.c Mon Oct 1 20:33:45 2007
      --- src/version.c Mon Oct 1 22:50:23 2007
      ***************
      *** 668,669 ****
      --- 668,671 ----
      { /* Add new patch number below this line */
      + /**/
      + 130,
      /**/

      --
      FIRST SOLDIER: So they wouldn't be able to bring a coconut back anyway.
      SECOND SOLDIER: Wait a minute! Suppose two swallows carried it together?
      FIRST SOLDIER: No, they'd have to have it on a line.
      "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

      /// 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
      -~----------~----~----~----~------~----~------~--~---
    • Bram Moolenaar
      ... I shouldn t send out patches late at night... The title should be without About ! -- CART DRIVER: Bring out your dead! We follow the cart through a
      Message 2 of 7 , Oct 2, 2007
        > Patch 7.1.130
        > Problem: Crash with specific order of undo and redo. (A.Politz)
        > Solution: Clear and adjust pointers properly. Add u_check() for debugging.
        > Files: src/undo.c, src/structs.h

        I shouldn't send out patches late at night... The title should be
        without "About"!

        --
        CART DRIVER: Bring out your dead!
        We follow the cart through a wretched, impoverished plague-ridden village.
        A few starved mongrels run about in the mud scavenging. In the open
        doorway of one house perhaps we jug glimpse a pair of legs dangling from
        the ceiling. In another doorway an OLD WOMAN is beating a cat against a
        wall rather like one does with a mat. The cart passes round a dead donkey
        or cow in the mud. And a MAN tied to a cart is being hammered to death by
        four NUNS with huge mallets.
        "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

        /// 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
        -~----------~----~----~----~------~----~------~--~---
      • Edward L. Fox
        ... Could you please tell me that which titles should be with About and which shouldn t? It seems that many patches these days are all with About prefix.
        Message 3 of 7 , Oct 2, 2007
          On 10/2/07, Bram Moolenaar <Bram@...> wrote:
          >
          >
          > > Patch 7.1.130
          > > Problem: Crash with specific order of undo and redo. (A.Politz)
          > > Solution: Clear and adjust pointers properly. Add u_check() for debugging.
          > > Files: src/undo.c, src/structs.h
          >
          > I shouldn't send out patches late at night... The title should be
          > without "About"!

          Could you please tell me that which titles should be with "About" and
          which shouldn't? It seems that many patches these days are all with
          "About" prefix.

          Any way, good night and sleep tight~


          >
          > --
          > CART DRIVER: Bring out your dead!
          > We follow the cart through a wretched, impoverished plague-ridden village.
          > A few starved mongrels run about in the mud scavenging. In the open
          > doorway of one house perhaps we jug glimpse a pair of legs dangling from
          > the ceiling. In another doorway an OLD WOMAN is beating a cat against a
          > wall rather like one does with a mat. The cart passes round a dead donkey
          > or cow in the mud. And a MAN tied to a cart is being hammered to death by
          > four NUNS with huge mallets.
          > "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
          >
          > /// 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 ///
          >
          > >
          >

          L. F.

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_dev" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Tony Mechelynck
          Edward L. Fox wrote: [...] ... [...] There was a recent thread about that. They all should be without, except the About post about patch 126. Best regards,
          Message 4 of 7 , Oct 2, 2007
            Edward L. Fox wrote:
            [...]
            > Could you please tell me that which titles should be with "About" and
            > which shouldn't? It seems that many patches these days are all with
            > "About" prefix.
            [...]

            There was a recent thread about that. They all should be without, except the
            "About" post about patch 126.

            Best regards,
            Tony.
            --
            Wit, n.:
            The salt with which the American Humorist spoils his cookery
            ... by leaving it out.
            -- Ambrose Bierce, "The Devil's Dictionary"

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_dev" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Andy Wokula
            ... Btw: How to reproduce this crash? -- Andy --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_dev maillist. For
            Message 5 of 7 , Oct 2, 2007
              Bram Moolenaar schrieb:
              > Patch 7.1.130
              > Problem: Crash with specific order of undo and redo. (A.Politz)
              > Solution: Clear and adjust pointers properly. Add u_check() for debugging.
              > Files: src/undo.c, src/structs.h

              Btw: How to reproduce this crash?

              --
              Andy

              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_dev" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • Bram Moolenaar
              ... A.Politz made this script: -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Function : Segfault Args : None Purpose : Called
              Message 6 of 7 , Oct 2, 2007
                Andy Wokula wrote:

                > Bram Moolenaar schrieb:
                > > Patch 7.1.130
                > > Problem: Crash with specific order of undo and redo. (A.Politz)
                > > Solution: Clear and adjust pointers properly. Add u_check() for debugging.
                > > Files: src/undo.c, src/structs.h
                >
                > Btw: How to reproduce this crash?

                A.Politz made this script:


                -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                "Function : Segfault
                "Args : None
                "Purpose : Called by the "UserGettingBored" aucommand.
                func! Segfault()
                setl noswapfile
                new
                setl noswapfile
                set undolevels=3
                put =0
                put =1
                set undolevels=3
                put =2
                set undolevels=3
                put =3
                set undolevels=3
                put =4
                set undolevels=1
                norm 3u
                set undolevels=3
                put =5
                set undolevels=1
                norm 3u
                endfun


                call Segfault()
                -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

                Even with some small changes it still crashes, tries to free memory
                that's already free, hangs, and other nasty things.

                --
                OLD WOMAN: Well, how did you become king, then?
                ARTHUR: The Lady of the Lake, her arm clad in the purest shimmering samite,
                held Excalibur aloft from the bosom of the water to signify by Divine
                Providence ... that I, Arthur, was to carry Excalibur ... That is
                why I am your king!
                "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

                /// 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
                -~----------~----~----~----~------~----~------~--~---
              • Bram Moolenaar
                ... None of the actual patches should have About in the subject. ... I will. But first finish reading all the messages... -- Bad programs can be written in
                Message 7 of 7 , Oct 2, 2007
                  Edward L. Fox wrote:

                  > On 10/2/07, Bram Moolenaar <Bram@...> wrote:
                  > >
                  > >
                  > > > Patch 7.1.130
                  > > > Problem: Crash with specific order of undo and redo. (A.Politz)
                  > > > Solution: Clear and adjust pointers properly. Add u_check() for debugging.
                  > > > Files: src/undo.c, src/structs.h
                  > >
                  > > I shouldn't send out patches late at night... The title should be
                  > > without "About"!
                  >
                  > Could you please tell me that which titles should be with "About" and
                  > which shouldn't? It seems that many patches these days are all with
                  > "About" prefix.

                  None of the actual patches should have "About" in the subject.

                  > Any way, good night and sleep tight~

                  I will. But first finish reading all the messages...

                  --
                  Bad programs can be written in any language.

                  /// 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.