Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
a30b172c
Commit
a30b172c
authored
Jan 11, 2012
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/printer: don't crash if AST contains BadXXX nodes
R=golang-dev, rsc CC=golang-dev
https://golang.org/cl/5535048
parent
b1bad553
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
1 deletion
+21
-1
src/pkg/go/printer/printer.go
src/pkg/go/printer/printer.go
+6
-1
src/pkg/go/printer/printer_test.go
src/pkg/go/printer/printer_test.go
+15
-0
No files found.
src/pkg/go/printer/printer.go
View file @
a30b172c
...
...
@@ -773,8 +773,13 @@ func (p *printer) print(args ...interface{}) {
next
=
p
.
fset
.
Position
(
x
)
// accurate position of next item
}
tok
=
p
.
lastTok
case
string
:
// incorrect AST - print error message
data
=
x
isLit
=
true
tok
=
token
.
STRING
default
:
fmt
.
Fprintf
(
os
.
Stderr
,
"print: unsupported argument
type %T
\n
"
,
f
)
fmt
.
Fprintf
(
os
.
Stderr
,
"print: unsupported argument
%v (%T)
\n
"
,
f
,
f
)
panic
(
"go/printer type"
)
}
p
.
lastTok
=
tok
...
...
src/pkg/go/printer/printer_test.go
View file @
a30b172c
...
...
@@ -204,3 +204,18 @@ func init() {
panic
(
"got "
+
s
+
", want "
+
name
)
}
}
// Verify that the printer doesn't crash if the AST contains BadXXX nodes.
func
TestBadNodes
(
t
*
testing
.
T
)
{
const
src
=
"package p
\n
("
const
res
=
"package p
\n
BadDecl
\n
"
f
,
err
:=
parser
.
ParseFile
(
fset
,
""
,
src
,
parser
.
ParseComments
)
if
err
==
nil
{
t
.
Errorf
(
"expected illegal program"
)
}
var
buf
bytes
.
Buffer
Fprint
(
&
buf
,
fset
,
f
)
if
buf
.
String
()
!=
res
{
t
.
Errorf
(
"got %q, expected %q"
,
buf
.
String
(),
res
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment