Mercurial > vim
annotate runtime/plugin/rrhelper.vim @ 33791:370543108ba1 v9.0.2114
patch 9.0.2114: overflow detection not accurate when adding digits
Commit: https://github.com/vim/vim/commit/22cbc8a4e17ce61aa460c451a26e1bff2c3d2af9
Author: Christian Brabandt <cb@256bit.org>
Date: Sun Nov 19 10:47:21 2023 +0100
patch 9.0.2114: overflow detection not accurate when adding digits
Problem: overflow detection not accurate when adding digits
Solution: Use a helper function
Use a helper function to better detect overflows before adding integer
digits to a long or an integer variable respectively. Signal the
overflow to the caller function.
closes: #13539
Signed-off-by: Christian Brabandt <cb@256bit.org>
Signed-off-by: Michael Henry <vim@drmikehenry.com>
Signed-off-by: Ernie Rael <errael@raelity.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 19 Nov 2023 11:00:07 +0100 |
parents | f177a6431514 |
children |
rev | line source |
---|---|
7 | 1 " Vim plugin with helper function(s) for --remote-wait |
2 " Maintainer: Flemming Madsen <fma@cci.dk> | |
1623 | 3 " Last Change: 2008 May 29 |
7 | 4 |
5 " Has this already been loaded? | |
2325
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
6 if exists("loaded_rrhelper") || !has("clientserver") |
7 | 7 finish |
8 endif | |
9 let loaded_rrhelper = 1 | |
10 | |
11 " Setup answers for a --remote-wait client who will assume | |
12 " a SetupRemoteReplies() function in the command server | |
13 | |
2325
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
14 function SetupRemoteReplies() |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
15 let cnt = 0 |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
16 let max = argc() |
7 | 17 |
2325
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
18 let id = expand("<client>") |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
19 if id == 0 |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
20 return |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
21 endif |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
22 while cnt < max |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
23 " Handle same file from more clients and file being more than once |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
24 " on the command line by encoding this stuff in the group name |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
25 let uniqueGroup = "RemoteReply_".id."_".cnt |
7 | 26 |
2325
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
27 " Path separators are always forward slashes for the autocommand pattern. |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
28 " Escape special characters with a backslash. |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
29 let f = substitute(argv(cnt), '\\', '/', "g") |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
30 if exists('*fnameescape') |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
31 let f = fnameescape(f) |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
32 else |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
33 let f = escape(f, " \t\n*?[{`$\\%#'\"|!<") |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
34 endif |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
35 execute "augroup ".uniqueGroup |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
36 execute "autocmd ".uniqueGroup." BufUnload ". f ." call DoRemoteReply('".id."', '".cnt."', '".uniqueGroup."', '". f ."')" |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
37 let cnt = cnt + 1 |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
38 endwhile |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
39 augroup END |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
40 endfunc |
7 | 41 |
2325
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
42 function DoRemoteReply(id, cnt, group, file) |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
43 call server2client(a:id, a:cnt) |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
44 execute 'autocmd! '.a:group.' BufUnload '.a:file |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
45 execute 'augroup! '.a:group |
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
1623
diff
changeset
|
46 endfunc |
7 | 47 |
48 " vim: set sw=2 sts=2 : |