good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
181a21c6
Commit
181a21c6
authored
10 years ago
by
Felix Lange
Browse files
Options
Downloads
Patches
Plain Diff
rlp: encode nil array pointers as empty list or string
parent
ff5578fc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
rlp/encode.go
+26
-8
26 additions, 8 deletions
rlp/encode.go
rlp/encode_test.go
+2
-0
2 additions, 0 deletions
rlp/encode_test.go
with
28 additions
and
8 deletions
rlp/encode.go
+
26
−
8
View file @
181a21c6
...
...
@@ -87,6 +87,8 @@ func (e flatenc) EncodeRLP(out io.Writer) error {
// To encode a pointer, the value being pointed to is encoded. For nil
// pointers, Encode will encode the zero value of the type. A nil
// pointer to a struct type always encodes as an empty RLP list.
// A nil pointer to an array encodes as an empty list (or empty string
// if the array has element type byte).
//
// Struct values are encoded as an RLP list of all their encoded
// public fields. Recursive struct types are supported.
...
...
@@ -532,21 +534,37 @@ func makePtrWriter(typ reflect.Type) (writer, error) {
if
err
!=
nil
{
return
nil
,
err
}
zero
:=
reflect
.
Zero
(
typ
.
Elem
())
// determine nil pointer handler
var
nilfunc
func
(
*
encbuf
)
error
kind
:=
typ
.
Elem
()
.
Kind
()
writer
:=
func
(
val
reflect
.
Value
,
w
*
encbuf
)
error
{
switch
{
case
!
val
.
IsNil
()
:
return
etypeinfo
.
writer
(
val
.
Elem
(),
w
)
case
kind
==
reflect
.
Struct
:
// encoding the zero value of a struct could trigger
switch
{
case
kind
==
reflect
.
Array
&&
isByte
(
typ
.
Elem
()
.
Elem
())
:
nilfunc
=
func
(
w
*
encbuf
)
error
{
w
.
str
=
append
(
w
.
str
,
0x80
)
return
nil
}
case
kind
==
reflect
.
Struct
||
kind
==
reflect
.
Array
:
nilfunc
=
func
(
w
*
encbuf
)
error
{
// encoding the zero value of a struct/array could trigger
// infinite recursion, avoid that.
w
.
listEnd
(
w
.
list
())
return
nil
default
:
}
default
:
zero
:=
reflect
.
Zero
(
typ
.
Elem
())
nilfunc
=
func
(
w
*
encbuf
)
error
{
return
etypeinfo
.
writer
(
zero
,
w
)
}
}
writer
:=
func
(
val
reflect
.
Value
,
w
*
encbuf
)
error
{
if
val
.
IsNil
()
{
return
nilfunc
(
w
)
}
else
{
return
etypeinfo
.
writer
(
val
.
Elem
(),
w
)
}
}
return
writer
,
err
}
...
...
This diff is collapsed.
Click to expand it.
rlp/encode_test.go
+
2
−
0
View file @
181a21c6
...
...
@@ -202,8 +202,10 @@ var encTests = []encTest{
{
val
:
(
*
uint
)(
nil
),
output
:
"80"
},
{
val
:
(
*
string
)(
nil
),
output
:
"80"
},
{
val
:
(
*
[]
byte
)(
nil
),
output
:
"80"
},
{
val
:
(
*
[
10
]
byte
)(
nil
),
output
:
"80"
},
{
val
:
(
*
big
.
Int
)(
nil
),
output
:
"80"
},
{
val
:
(
*
[]
string
)(
nil
),
output
:
"C0"
},
{
val
:
(
*
[
10
]
string
)(
nil
),
output
:
"C0"
},
{
val
:
(
*
[]
interface
{})(
nil
),
output
:
"C0"
},
{
val
:
(
*
[]
struct
{
uint
})(
nil
),
output
:
"C0"
},
{
val
:
(
*
interface
{})(
nil
),
output
:
"C0"
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment