]> granicus.if.org Git - vim/commitdiff
patch 8.2.2547: "%" command not accurate for big files v8.2.2547
authorBram Moolenaar <Bram@vim.org>
Tue, 23 Feb 2021 18:32:03 +0000 (19:32 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 23 Feb 2021 18:32:03 +0000 (19:32 +0100)
Problem:    "%" command not accurate for big files.
Solution:   Make it more accurate for files up to 21M lines. (Dominique PellĂ©,
            closes #7889)

src/normal.c
src/version.c

index 9fbfadfbc71450841667cd0ff9d30f8c0cbd8a5c..d2f41593a01b95094ded90c78a9d48474959bc8f 100644 (file)
@@ -4769,9 +4769,11 @@ nv_percent(cmdarg_T *cap)
        {
            cap->oap->motion_type = MLINE;
            setpcmark();
-           // Round up, so CTRL-G will give same value.  Watch out for a
-           // large line count, the line number must not go negative!
-           if (curbuf->b_ml.ml_line_count > 1000000)
+           // Round up, so 'normal 100%' always jumps at the line line.
+           // Beyond 21474836 lines, (ml_line_count * 100 + 99) would
+           // overflow on 32-bits, so use a formula with less accuracy
+           // to avoid overflows.
+           if (curbuf->b_ml.ml_line_count >= 21474836)
                curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L)
                                                         / 100L * cap->count0;
            else
index c63e60c3d9d48765b6480b138a5fcd27aa666c29..7eb0d057af4818e592520f55812d427604076137 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2547,
 /**/
     2546,
 /**/