Mercurial > vim
annotate runtime/ftplugin/spec.vim @ 33488:0081ca43bee9 v9.0.1995
patch 9.0.1995: Invalid memory access with empty 'foldexpr'
Commit: https://github.com/vim/vim/commit/a991ce9c083bb8c02b1b1ec34ed35728197050f3
Author: zeertzjq <zeertzjq@outlook.com>
Date: Fri Oct 6 19:16:36 2023 +0200
patch 9.0.1995: Invalid memory access with empty 'foldexpr'
Problem: Invalid memory access when 'foldexpr' returns empty string.
Solution: Check for NUL.
closes: #13293
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 06 Oct 2023 19:30:07 +0200 |
parents | 57c9377b9c62 |
children | 590ab2c926e6 |
rev | line source |
---|---|
7 | 1 " Plugin to update the %changelog section of RPM spec files |
2 " Filename: spec.vim | |
5697 | 3 " Maintainer: Igor Gnatenko i.gnatenko.brain@gmail.com |
4 " Former Maintainer: Gustavo Niemeyer <niemeyer@conectiva.com> (until March 2014) | |
6823 | 5 " Last Change: Mon Jun 01 21:15 MSK 2015 Igor Gnatenko |
28933 | 6 " Update by Zdenek Dohnal, 2022 May 17 |
7 | 7 |
8 if exists("b:did_ftplugin") | |
9 finish | |
10 endif | |
11 let b:did_ftplugin = 1 | |
12 | |
3237 | 13 let s:cpo_save = &cpo |
14 set cpo&vim | |
15 | |
7 | 16 if !exists("no_plugin_maps") && !exists("no_spec_maps") |
17 if !hasmapto("<Plug>SpecChangelog") | |
18 map <buffer> <LocalLeader>c <Plug>SpecChangelog | |
19 endif | |
20 endif | |
21 | |
26100 | 22 if !hasmapto("call <SID>SpecChangelog(\"\")<CR>") |
23 noremap <buffer> <unique> <script> <Plug>SpecChangelog :call <SID>SpecChangelog("")<CR> | |
6647 | 24 endif |
7 | 25 |
6823 | 26 if !exists("*s:GetRelVer") |
27 function! s:GetRelVer() | |
28 if has('python') | |
29 python << PYEND | |
30 import sys, datetime, shutil, tempfile | |
31 import vim | |
32 | |
33 try: | |
34 import rpm | |
35 except ImportError: | |
36 pass | |
37 else: | |
38 specfile = vim.current.buffer.name | |
39 if specfile: | |
9227
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
40 rpm.delMacro("dist") |
6823 | 41 spec = rpm.spec(specfile) |
9227
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
42 headers = spec.sourceHeader |
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
43 version = headers["Version"] |
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
44 release = headers["Release"] |
28933 | 45 vim.command("let ver = '" + version + "'") |
46 vim.command("let rel = '" + release + "'") | |
6823 | 47 PYEND |
48 endif | |
49 endfunction | |
50 endif | |
51 | |
7 | 52 if !exists("*s:SpecChangelog") |
53 function s:SpecChangelog(format) | |
54 if strlen(a:format) == 0 | |
55 if !exists("g:spec_chglog_format") | |
6823 | 56 let email = input("Name <email address>: ") |
7 | 57 let g:spec_chglog_format = "%a %b %d %Y " . l:email |
58 echo "\r" | |
59 endif | |
60 let format = g:spec_chglog_format | |
61 else | |
62 if !exists("g:spec_chglog_format") | |
63 let g:spec_chglog_format = a:format | |
64 endif | |
65 let format = a:format | |
66 endif | |
67 let line = 0 | |
68 let name = "" | |
69 let ver = "" | |
70 let rel = "" | |
71 let nameline = -1 | |
72 let verline = -1 | |
73 let relline = -1 | |
74 let chgline = -1 | |
75 while (line <= line("$")) | |
76 let linestr = getline(line) | |
23305 | 77 if name == "" && linestr =~? '^Name:' |
7 | 78 let nameline = line |
79 let name = substitute(strpart(linestr,5), '^[ ]*\([^ ]\+\)[ ]*$','\1','') | |
23305 | 80 elseif ver == "" && linestr =~? '^Version:' |
7 | 81 let verline = line |
82 let ver = substitute(strpart(linestr,8), '^[ ]*\([^ ]\+\)[ ]*$','\1','') | |
23305 | 83 elseif rel == "" && linestr =~? '^Release:' |
7 | 84 let relline = line |
85 let rel = substitute(strpart(linestr,8), '^[ ]*\([^ ]\+\)[ ]*$','\1','') | |
23305 | 86 elseif linestr =~? '^%changelog' |
7 | 87 let chgline = line |
88 execute line | |
89 break | |
90 endif | |
91 let line = line+1 | |
92 endwhile | |
23305 | 93 if nameline != -1 && verline != -1 && relline != -1 |
7 | 94 let include_release_info = exists("g:spec_chglog_release_info") |
95 let name = s:ParseRpmVars(name, nameline) | |
96 let ver = s:ParseRpmVars(ver, verline) | |
97 let rel = s:ParseRpmVars(rel, relline) | |
98 else | |
99 let include_release_info = 0 | |
100 endif | |
6823 | 101 |
102 call s:GetRelVer() | |
103 | |
23305 | 104 if chgline == -1 |
7 | 105 let option = confirm("Can't find %changelog. Create one? ","&End of file\n&Here\n&Cancel",3) |
23305 | 106 if option == 1 |
7 | 107 call append(line("$"),"") |
108 call append(line("$"),"%changelog") | |
109 execute line("$") | |
110 let chgline = line(".") | |
23305 | 111 elseif option == 2 |
7 | 112 call append(line("."),"%changelog") |
113 normal j | |
23305 | 114 let chgline = line(".") |
7 | 115 endif |
116 endif | |
23305 | 117 if chgline != -1 |
9227
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
118 let tmptime = v:lc_time |
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
119 language time C |
6823 | 120 let parsed_format = "* ".strftime(format)." - ".ver."-".rel |
9227
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
121 execute "language time" tmptime |
7 | 122 let release_info = "+ ".name."-".ver."-".rel |
123 let wrong_format = 0 | |
124 let wrong_release = 0 | |
125 let insert_line = 0 | |
23305 | 126 if getline(chgline+1) != parsed_format |
7 | 127 let wrong_format = 1 |
128 endif | |
23305 | 129 if include_release_info && getline(chgline+2) != release_info |
7 | 130 let wrong_release = 1 |
131 endif | |
23305 | 132 if wrong_format || wrong_release |
133 if include_release_info && !wrong_release && !exists("g:spec_chglog_never_increase_release") | |
7 | 134 let option = confirm("Increase release? ","&Yes\n&No",1) |
23305 | 135 if option == 1 |
7 | 136 execute relline |
137 normal | |
138 let rel = substitute(strpart(getline(relline),8), '^[ ]*\([^ ]\+\)[ ]*$','\1','') | |
139 let release_info = "+ ".name."-".ver."-".rel | |
140 endif | |
141 endif | |
142 let n = 0 | |
143 call append(chgline+n, parsed_format) | |
144 if include_release_info | |
145 let n = n + 1 | |
146 call append(chgline+n, release_info) | |
147 endif | |
148 let n = n + 1 | |
149 call append(chgline+n,"- ") | |
150 let n = n + 1 | |
151 call append(chgline+n,"") | |
152 let insert_line = chgline+n | |
153 else | |
154 let line = chgline | |
155 if !exists("g:spec_chglog_prepend") | |
156 while !(getline(line+2) =~ '^\( *\|\*.*\)$') | |
157 let line = line+1 | |
158 endwhile | |
159 endif | |
160 call append(line+1,"- ") | |
161 let insert_line = line+2 | |
162 endif | |
163 execute insert_line | |
164 startinsert! | |
165 endif | |
166 endfunction | |
167 endif | |
168 | |
169 if !exists("*s:ParseRpmVars") | |
170 function s:ParseRpmVars(str, strline) | |
171 let end = -1 | |
172 let ret = "" | |
173 while (1) | |
174 let start = match(a:str, "\%{", end+1) | |
23305 | 175 if start == -1 |
7 | 176 let ret = ret . strpart(a:str, end+1) |
177 break | |
178 endif | |
179 let ret = ret . strpart(a:str, end+1, start-(end+1)) | |
180 let end = match(a:str, "}", start) | |
23305 | 181 if end == -1 |
7 | 182 let ret = ret . strpart(a:str, start) |
183 break | |
184 endif | |
185 let varname = strpart(a:str, start+2, end-(start+2)) | |
186 execute a:strline | |
22171 | 187 let definestr = "^[ \t]*%\\(define\\|global\\)[ \t]\\+".varname."[ \t]\\+\\(.*\\)$" |
7 | 188 let linenum = search(definestr, "bW") |
23305 | 189 if linenum != 0 |
22171 | 190 let ret = ret . substitute(getline(linenum), definestr, "\\2", "") |
7 | 191 endif |
192 endwhile | |
193 return ret | |
194 endfunction | |
195 endif | |
196 | |
197 " The following lines, along with the macros/matchit.vim plugin, | |
198 " make it easy to navigate the different sections of a spec file | |
199 " with the % key (thanks to Max Ischenko). | |
200 | |
201 let b:match_ignorecase = 0 | |
202 let b:match_words = | |
9227
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
203 \ '^Name:^%description:^%clean:^%(?:auto)?setup:^%build:^%install:^%files:' . |
7 | 204 \ '^%package:^%preun:^%postun:^%changelog' |
205 | |
3237 | 206 let &cpo = s:cpo_save |
207 unlet s:cpo_save | |
208 | |
3410
94601b379f38
Updated runtime files. Add Dutch translations.
Bram Moolenaar <bram@vim.org>
parents:
3237
diff
changeset
|
209 let b:undo_ftplugin = "unlet! b:match_ignorecase b:match_words" |