Mercurial > vim
annotate runtime/syntax/lex.vim @ 26773:80e134cbee4b v8.2.3915
patch 8.2.3915: illegal memory access when completing with invalid bytes
Commit: https://github.com/vim/vim/commit/4b28ba3245df8274303c79429972f9dc9438e4aa
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Dec 27 19:28:37 2021 +0000
patch 8.2.3915: illegal memory access when completing with invalid bytes
Problem: illegal memory access when completing with invalid bytes.
Solution: Avoid going over the end of the completion text.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 27 Dec 2021 20:30:03 +0100 |
parents | 29c5f168c6fd |
children | 02bd0fe77c68 |
rev | line source |
---|---|
7 | 1 " Vim syntax file |
20241 | 2 " Language: Lex and Flex |
19180 | 3 " Maintainer: Charles E. Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> |
20241 | 4 " Contributor: Robert A. van Engelen <engelen@acm.org> |
5 " Last Change: Apr 24, 2020 | |
6 " Version: 18 | |
7 | 7 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
3920
diff
changeset
|
8 " quit when a syntax file was already loaded |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
3920
diff
changeset
|
9 if exists("b:current_syntax") |
7 | 10 finish |
11 endif | |
12 | |
20241 | 13 " Read the C++ syntax to start with |
14 let s:Cpath= fnameescape(expand("<sfile>:p:h")."/cpp.vim") | |
3920 | 15 if !filereadable(s:Cpath) |
20241 | 16 for s:Cpath in split(globpath(&rtp,"syntax/cpp.vim"),"\n") |
3920 | 17 if filereadable(fnameescape(s:Cpath)) |
18 let s:Cpath= fnameescape(s:Cpath) | |
19 break | |
7 | 20 endif |
3920 | 21 endfor |
7 | 22 endif |
3920 | 23 exe "syn include @lexCcode ".s:Cpath |
7 | 24 |
22 | 25 " --- ========= --- |
7 | 26 " --- Lex stuff --- |
22 | 27 " --- ========= --- |
7 | 28 |
20241 | 29 " Definitions |
30 " %% | |
31 " Rules | |
32 " %% | |
33 " User Code | |
34 " | |
35 " --- ======= --- | |
36 " --- Example --- | |
37 " --- ======= --- | |
38 " | |
39 " // this is a valid lex file | |
40 " // indented initial code block | |
41 " #include <stdlib.h> | |
42 " %{ | |
43 " // initial code block | |
44 " #include <stdio.h> | |
45 " const char *sep = ""; | |
46 " %} | |
47 " %option outfile="scanner.c" noyywrap nodefault | |
48 " %x COMMENT | |
49 " id [A-Za-z_][A-Za-z0-9_]* | |
50 " %% | |
51 " // indented initial action code block | |
52 " printf("BEGIN"); | |
53 " {id} printf("%s%s", sep, yytext); sep = ""; | |
54 " . | | |
55 " \n { sep = "\n"; } | |
56 " "/*" { BEGIN COMMENT; } | |
57 " "//".* { } | |
58 " <COMMENT>{ | |
59 " "*/" { BEGIN INITIAL; } | |
60 " .|\n | |
61 " } | |
62 " <*><<EOF>> { // end of file | |
63 " printf("\nEND\n"); | |
64 " yyterminate(); | |
65 " } | |
66 " %% | |
67 " void scan() | |
68 " { | |
69 " while (yylex()) | |
70 " continue; | |
71 " } | |
72 " /* main program */ | |
73 " int main() | |
74 " { | |
75 " scan(); | |
76 " } | |
2662 | 77 |
20241 | 78 " Definitions Section with initial code blocks, abbreviations, options, states |
2034 | 79 if has("folding") |
20241 | 80 syn region lexAbbrvBlock fold start="^\S" end="^\ze%%" skipnl nextgroup=lexPatBlock contains=lexOptions,lexAbbrv,lexInitialCodeBlock,lexInclude,lexAbbrvComment,lexStartState |
2034 | 81 else |
20241 | 82 syn region lexAbbrvBlock start="^\S" end="^\ze%%" skipnl nextgroup=lexPatBlock contains=lexOptions,lexAbbrv,lexInitialCodeBlock,lexInclude,lexAbbrvComment,lexStartState |
2034 | 83 endif |
20241 | 84 syn match lexOptions "^%\a\+\(\s.*\|[^{]*\)$" contains=lexOptionsEq,lexPatString,lexSlashQuote,lexBrace,lexSlashBrace |
85 syn match lexOptionsEq "=" skipwhite contained | |
86 syn match lexAbbrv "^\I\i*\s"me=e-1 skipwhite contained nextgroup=lexAbbrvPat | |
87 syn match lexAbbrvPat "\s\S.*$"lc=1 contained contains=lexPatAbbrv,lexPatString,lexSlashQuote,lexBrace,lexSlashBrace nextgroup=lexAbbrv,lexInclude | |
88 syn match lexStartState "^%\(xs\?\|s\)\(t\(a\(t\(e\?\)\?\)\?\)\?\)\?\(\s\+\I\i*\)\+\s*$" contained contains=lexStartStateCmd | |
89 syn match lexStartStateCmd '^%\(xs\?\|s\)\(t\(a\(t\(e\?\)\?\)\?\)\?\)\?' contained | |
2034 | 90 if has("folding") |
20241 | 91 syn region lexInitialCodeBlock fold start="^\s\+" end="^\S"me=e-1 contains=@lexCcode |
92 syn region lexInclude fold matchgroup=lexSep start="^%\a*{" end="^%\?}" contained contains=@lexCcode,lexCFunctions | |
93 syn region lexAbbrvComment fold start="^\s*//" end="$" contains=@Spell | |
94 syn region lexAbbrvComment fold start="^\s*/\*" end="\*/" contains=@Spell | |
2034 | 95 else |
20241 | 96 syn region lexInitialCodeBlock start="^\s\+" end="^\S"me=e-1 contains=@lexCcode |
97 syn region lexInclude matchgroup=lexSep start="^%\a*{" end="^%\?}" contained contains=@lexCcode,lexCFunctions | |
98 syn region lexAbbrvComment start="^\s*//" end="$" contains=@Spell | |
99 syn region lexAbbrvComment start="^\s*/\*" end="\*/" contains=@Spell | |
2034 | 100 endif |
7 | 101 |
20241 | 102 " Rules Section with patterns and actions |
2034 | 103 if has("folding") |
20241 | 104 syn region lexPatBlock fold matchgroup=Todo start="^%%" matchgroup=Todo end="^\ze%%" skipnl skipwhite nextgroup=lexFinalCodeBlock contains=lexPatTag,lexPatTagZone,lexPatComment,lexPat,lexPatSep,lexPatInclude |
105 syn region lexPat fold start="\S" skip="\\\\\|\\\s" end="\ze\(\s*$\|\s\+\(\h\|{\W\|{$\|[-+*]\|//\|/\*\)\)" skipwhite contained nextgroup=lexMorePat,lexPatSep,lexPatEnd contains=lexPatTag,lexPatString,lexSlashQuote,lexPatAbbrv,lexBrace,lexSlashBrace | |
106 syn region lexPatInclude fold matchgroup=lexSep start="^%{" end="^%}" contained contains=@lexCcode | |
107 syn region lexBrace fold matchgroup=Character start="\[" skip="\\.\|\[:\a\+:\]\|\[\.\a\+\.\]\|\[=.=\]" end="\]" contained | |
108 syn region lexPatString fold matchgroup=String start=+"+ skip=+\\\\\|\\"+ matchgroup=String end=+"+ contained | |
2034 | 109 else |
20241 | 110 syn region lexPatBlock matchgroup=Todo start="^%%" matchgroup=Todo end="^\ze%%" skipnl skipwhite nextgroup=lexFinalCodeBlock contains=lexPatTag,lexPatTagZone,lexPatComment,lexPat,lexPatSep,lexPatInclude |
111 syn region lexPat start="\S" skip="\\\\\|\\\s" end="\ze\(\s*$\|\s\+\(\h\|{\W\|{$\|[-+*]\|//\|/\*\)\)" skipwhite contained nextgroup=lexMorePat,lexPatSep,lexPatEnd contains=lexPatTag,lexPatString,lexSlashQuote,lexPatAbbrv,lexBrace,lexSlashBrace | |
112 syn region lexPatInclude matchgroup=lexSep start="^%{" end="^%}" contained contains=@lexCcode | |
113 syn region lexBrace matchgroup=Character start="\[" skip="\\.\|\[:\a\+:\]\|\[\.\a\+\.\]\|\[=.=\]" end="\]" contained | |
114 syn region lexPatString matchgroup=String start=+"+ skip=+\\\\\|\\"+ matchgroup=String end=+"+ contained | |
2034 | 115 endif |
20241 | 116 syn match lexPatAbbrv "{\I\i*}"hs=s+1,he=e-1 contained |
117 syn match lexPatTag "^<\^\?\(\I\i*\|\*\)\(,\^\?\(\I\i*\|\*\)\)*>" contained nextgroup=lexPat,lexMorePat,lexPatSep,lexPatEnd | |
118 syn match lexPatTagZone "^<\^\?\(\I\i*\|\*\)\(,\^\?\(\I\i*\|\*\)\)*>\s*{$"me=e-1 contained nextgroup=lexPatTagZoneStart | |
3920 | 119 |
2034 | 120 if has("folding") |
20241 | 121 syn region lexPatTagZoneStart fold matchgroup=lexPatTag start='{$' end='^}' skipnl skipwhite contained contains=lexPatTag,lexPatTagZone,lexPatComment,lexPat,lexPatSep,lexPatInclude |
122 syn region lexPatComment fold start="//" end="$" skipnl contained contains=cTodo skipwhite nextgroup=lexPatComment,lexPat,@Spell | |
123 syn region lexPatComment fold start="/\*" end="\*/" skipnl contained contains=cTodo skipwhite nextgroup=lexPatComment,lexPat,@Spell | |
2034 | 124 else |
23047 | 125 syn region lexPatTagZoneStart matchgroup=lexPatTag start='{' end='^}' skipnl skipwhite contained contains=lexPatTag,lexPatTagZone,lexPatComment,lexPat,lexPatSep,lexPatInclude |
20241 | 126 syn region lexPatComment start="//" end="$" skipnl contained contains=cTodo skipwhite nextgroup=lexPatComment,lexPat,@Spell |
127 syn region lexPatComment start="/\*" end="\*/" skipnl contained contains=cTodo skipwhite nextgroup=lexPatComment,lexPat,@Spell | |
2034 | 128 endif |
20241 | 129 syn match lexPatEnd "\s*$" skipnl contained |
130 syn match lexPatCodeLine "[^{\[].*" contained contains=@lexCcode,lexCFunctions | |
131 syn match lexMorePat "\s*|\s*$" skipnl contained nextgroup=lexPat,lexPatTag,lexPatComment | |
132 syn match lexPatSep "\s\+" contained nextgroup=lexMorePat,lexPatCode,lexPatCodeLine | |
7 | 133 syn match lexSlashQuote +\(\\\\\)*\\"+ contained |
20241 | 134 syn match lexSlashBrace +\(\\\\\)*\\\[+ contained |
2034 | 135 if has("folding") |
20241 | 136 syn region lexPatCode fold matchgroup=Delimiter start="{" end="}" skipnl contained contains=@lexCcode,lexCFunctions |
2034 | 137 else |
20241 | 138 syn region lexPatCode matchgroup=Delimiter start="{" end="}" skipnl contained contains=@lexCcode,lexCFunctions |
2034 | 139 endif |
7 | 140 |
20241 | 141 " User Code Section with final code block |
142 syn region lexFinalCodeBlock matchgroup=Todo start="^%%" end="\%$" contained contains=@lexCcode | |
7 | 143 |
20241 | 144 " Lex macros which may appear in C/C++ code blocks |
145 syn keyword lexCFunctions BEGIN ECHO REJECT yytext YYText yyleng YYLeng yymore yyless yywrap yylook | |
146 syn keyword lexCFunctions yyrestart yyterminate yylineno yycolumno yyin yyout | |
147 syn keyword lexCFunctions input unput output winput wunput woutput | |
148 syn keyword lexCFunctions yyinput yyunput yyoutput yywinput yywunput yywoutput | |
3920 | 149 |
7 | 150 " <c.vim> includes several ALLBUTs; these have to be treated so as to exclude lex* groups |
20241 | 151 syn cluster cParenGroup add=lex.* |
7 | 152 syn cluster cDefineGroup add=lex.* |
153 syn cluster cPreProcGroup add=lex.* | |
20241 | 154 syn cluster cMultiGroup add=lex.* |
7 | 155 |
156 " Synchronization | |
157 syn sync clear | |
3920 | 158 syn sync minlines=500 |
7 | 159 syn sync match lexSyncPat grouphere lexPatBlock "^%[a-zA-Z]" |
160 syn sync match lexSyncPat groupthere lexPatBlock "^<$" | |
20241 | 161 syn sync match lexSyncPat groupthere lexPatBlock "^%%" |
7 | 162 |
163 " The default highlighting. | |
10051
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
164 if !exists("skip_lex_syntax_inits") |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
165 hi def link lexAbbrvComment lexPatComment |
20241 | 166 hi def link lexAbbrvPat lexPat |
167 hi def link lexAbbrv Special | |
168 hi def link lexBrace lexPat | |
169 hi def link lexCFunctions PreProc | |
170 hi def link lexMorePat Special | |
171 hi def link lexOptions PreProc | |
172 hi def link lexOptionsEq Operator | |
10051
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
173 hi def link lexPatComment Comment |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
174 hi def link lexPat Function |
20241 | 175 hi def link lexPatString lexPat |
176 hi def link lexPatAbbrv Special | |
177 hi def link lexPatTag Statement | |
10051
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
178 hi def link lexPatTagZone lexPatTag |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
179 hi def link lexSep Delimiter |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
180 hi def link lexSlashQuote lexPat |
20241 | 181 hi def link lexSlashBrace lexPat |
182 hi def link lexStartState lexPatTag | |
183 hi def link lexStartStateCmd Special | |
10051
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
184 endif |
7 | 185 |
186 let b:current_syntax = "lex" | |
187 | |
20241 | 188 " vim:ts=8 |