Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
6f66a89d
Commit
6f66a89d
authored
Apr 22, 2017
by
David Renshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug where struct equality could ignore some pointer fields.
parent
cfd813e4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
1 deletion
+46
-1
any-test.c++
c++/src/capnp/any-test.c++
+32
-0
any.c++
c++/src/capnp/any.c++
+14
-1
No files found.
c++/src/capnp/any-test.c++
View file @
6f66a89d
...
...
@@ -402,6 +402,38 @@ KJ_TEST("Pointer list unequal to struct list") {
EXPECT_EQ
(
Equality
::
NOT_EQUAL
,
message1
.
getRoot
<
AnyList
>
().
equals
(
message2
.
getRoot
<
AnyList
>
()));
}
KJ_TEST
(
"Truncating non-null pointer fields does not preserve equality"
)
{
AlignedData
<
3
>
segment1
=
{{
// list with one data word and one pointer field
0x00
,
0x00
,
0x00
,
0x00
,
0x01
,
0x00
,
0x01
,
0x00
,
// data word
0xab
,
0xab
,
0xab
,
0xab
,
0xab
,
0xab
,
0xab
,
0xab
,
// non-null pointer to zero-sized struct
0xfc
,
0xff
,
0xff
,
0xff
,
0x00
,
0x00
,
0x00
,
0x00
,
}};
kj
::
ArrayPtr
<
const
word
>
segments1
[
1
]
=
{
kj
::
arrayPtr
(
segment1
.
words
,
3
)
};
SegmentArrayMessageReader
message1
(
kj
::
arrayPtr
(
segments1
,
1
));
AlignedData
<
2
>
segment2
=
{{
// list with one data word and zero pointers
0x00
,
0x00
,
0x00
,
0x00
,
0x01
,
0x00
,
0x00
,
0x00
,
// data word
0xab
,
0xab
,
0xab
,
0xab
,
0xab
,
0xab
,
0xab
,
0xab
,
}};
kj
::
ArrayPtr
<
const
word
>
segments2
[
1
]
=
{
kj
::
arrayPtr
(
segment2
.
words
,
2
)
};
SegmentArrayMessageReader
message2
(
kj
::
arrayPtr
(
segments2
,
1
));
EXPECT_EQ
(
Equality
::
NOT_EQUAL
,
message1
.
getRoot
<
AnyPointer
>
().
equals
(
message2
.
getRoot
<
AnyPointer
>
()));
}
}
// namespace
}
// namespace _ (private)
}
// namespace capnp
c++/src/capnp/any.c++
View file @
6f66a89d
...
...
@@ -101,12 +101,25 @@ Equality AnyStruct::Reader::equals(AnyStruct::Reader right) {
}
auto
ptrsL
=
getPointerSection
();
size_t
ptrsSizeL
=
ptrsL
.
size
();
while
(
ptrsSizeL
>
0
&&
ptrsL
[
ptrsSizeL
-
1
].
isNull
())
{
--
ptrsSizeL
;
}
auto
ptrsR
=
right
.
getPointerSection
();
size_t
ptrsSizeR
=
ptrsR
.
size
();
while
(
ptrsSizeR
>
0
&&
ptrsR
[
ptrsSizeR
-
1
].
isNull
())
{
--
ptrsSizeR
;
}
if
(
ptrsSizeL
!=
ptrsSizeR
)
{
return
Equality
::
NOT_EQUAL
;
}
size_t
i
=
0
;
auto
eqResult
=
Equality
::
EQUAL
;
for
(;
i
<
kj
::
min
(
ptrsL
.
size
(),
ptrsR
.
size
())
;
i
++
)
{
for
(;
i
<
ptrsSizeL
;
i
++
)
{
auto
l
=
ptrsL
[
i
];
auto
r
=
ptrsR
[
i
];
switch
(
l
.
equals
(
r
))
{
...
...
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