Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
2226acb4
Unverified
Commit
2226acb4
authored
Aug 05, 2020
by
Janoš Guljaš
Committed by
GitHub
Aug 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent panic in proximity function with shorter second argument (#517)
parent
fb8473da
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
proximity.go
pkg/swarm/proximity.go
+4
-2
proximity_test.go
pkg/swarm/proximity_test.go
+20
-0
No files found.
pkg/swarm/proximity.go
View file @
2226acb4
...
...
@@ -19,8 +19,10 @@ package swarm
// (0 farthest, 255 closest, 256 self)
func
Proximity
(
one
,
other
[]
byte
)
(
ret
uint8
)
{
b
:=
MaxPO
/
8
+
1
l
:=
uint8
(
len
(
one
))
if
b
>
l
{
if
l
:=
uint8
(
len
(
one
));
b
>
l
{
b
=
l
}
if
l
:=
uint8
(
len
(
other
));
b
>
l
{
b
=
l
}
var
m
uint8
=
8
...
...
pkg/swarm/proximity_test.go
View file @
2226acb4
...
...
@@ -168,10 +168,30 @@ func TestProximity(t *testing.T) {
addr
:
[]
byte
{
0
b00000000
,
0
b00000000
,
0
b00000000
,
0
b00000001
},
po
:
limitPO
(
31
),
},
{
addr
:
nil
,
po
:
limitPO
(
31
),
},
{
addr
:
[]
byte
{
0
b00000001
},
po
:
limitPO
(
7
),
},
{
addr
:
[]
byte
{
0
b00000000
},
po
:
limitPO
(
31
),
},
{
addr
:
[]
byte
{
0
b00000000
,
0
b00000000
,
0
b00000000
,
0
b00000000
,
0
b00000001
},
po
:
limitPO
(
31
),
},
}
{
got
:=
Proximity
(
base
,
tc
.
addr
)
if
got
!=
tc
.
po
{
t
.
Errorf
(
"got %v bin, want %v"
,
got
,
tc
.
po
)
}
got
=
Proximity
(
tc
.
addr
,
base
)
if
got
!=
tc
.
po
{
t
.
Errorf
(
"got %v bin, want %v (reverse arguments)"
,
got
,
tc
.
po
)
}
}
}
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