Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
ff3ea68e
Commit
ff3ea68e
authored
Dec 02, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
explicitly catch attempt to decode into a value - must be a pointer to see the result.
R=rsc
https://golang.org/cl/163070
parent
f9810f1b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
2 deletions
+20
-2
decoder.go
src/pkg/gob/decoder.go
+7
-0
encoder_test.go
src/pkg/gob/encoder_test.go
+13
-2
No files found.
src/pkg/gob/decoder.go
View file @
ff3ea68e
...
...
@@ -58,6 +58,13 @@ func (dec *Decoder) recvType(id typeId) {
// The value underlying e must be the correct type for the next
// data item received.
func
(
dec
*
Decoder
)
Decode
(
e
interface
{})
os
.
Error
{
// If e represents a value, the answer won't get back to the
// caller. Make sure it's a pointer.
if
_
,
ok
:=
reflect
.
Typeof
(
e
)
.
(
*
reflect
.
PtrType
);
!
ok
{
dec
.
state
.
err
=
os
.
ErrorString
(
"gob: attempt to decode into a non-pointer"
);
return
dec
.
state
.
err
;
}
// Make sure we're single-threaded through here.
dec
.
mutex
.
Lock
();
defer
dec
.
mutex
.
Unlock
();
...
...
src/pkg/gob/encoder_test.go
View file @
ff3ea68e
...
...
@@ -9,6 +9,7 @@ import (
"io"
;
"os"
;
"reflect"
;
"strings"
;
"testing"
;
)
...
...
@@ -195,7 +196,6 @@ func TestPtrTypeToType(t *testing.T) {
}
func
TestTypeToPtrPtrPtrPtrType
(
t
*
testing
.
T
)
{
// Encode a *T, decode a T
type
Type2
struct
{
a
****
float
;
}
...
...
@@ -215,7 +215,6 @@ func TestTypeToPtrPtrPtrPtrType(t *testing.T) {
}
func
TestSlice
(
t
*
testing
.
T
)
{
// Encode a *T, decode a T
type
Type3
struct
{
a
[]
string
;
}
...
...
@@ -225,3 +224,15 @@ func TestSlice(t *testing.T) {
t
.
Error
(
err
)
}
}
func
TestValueError
(
t
*
testing
.
T
)
{
// Encode a *T, decode a T
type
Type4
struct
{
a
int
;
}
t4p
:=
Type4
{
3
};
// note: not a pointer, unlike the other tests.
var
t4
Type4
;
if
err
:=
encAndDec
(
t4
,
t4p
);
err
==
nil
||
strings
.
Index
(
err
.
String
(),
"pointer"
)
<=
0
{
t
.
Error
(
"expected error; got none or got wrong one"
)
}
}
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