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
59267d01
Unverified
Commit
59267d01
authored
Dec 12, 2018
by
Kenton Varda
Committed by
GitHub
Dec 12, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #774 from capnproto/harris/debug-vector-output-stream
Log more info in VectorOutputStream::write() KJ_REQUIRE
parents
18e966cb
9ffbfda8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
4 deletions
+26
-4
io-test.c++
c++/src/kj/io-test.c++
+22
-0
io.c++
c++/src/kj/io.c++
+4
-4
No files found.
c++/src/kj/io-test.c++
View file @
59267d01
...
...
@@ -175,5 +175,27 @@ KJ_TEST("InputStream::readAllText() / readAllBytes()") {
}
}
KJ_TEST
(
"ArrayOutputStream::write() does not assume adjacent write buffer is its own"
)
{
// Previously, if ArrayOutputStream::write(src, size) saw that `src` equaled its fill position, it
// would assume that the write was already in its buffer. This assumption was buggy if the write
// buffer was directly adjacent in memory to the ArrayOutputStream's buffer, and the
// ArrayOutputStream was full (i.e., its fill position was one-past-the-end).
//
// VectorOutputStream also suffered a similar bug, but it is much harder to test, since it
// performs its own allocation.
kj
::
byte
buffer
[
10
]
=
{
0
};
ArrayOutputStream
output
(
arrayPtr
(
buffer
,
buffer
+
5
));
// Succeeds and fills the ArrayOutputStream.
output
.
write
(
buffer
+
5
,
5
);
// Previously this threw an inscrutable "size <= array.end() - fillPos" requirement failure.
KJ_EXPECT_THROW_MESSAGE
(
"backing array was not large enough for the data written"
,
output
.
write
(
buffer
+
5
,
5
));
}
}
// namespace
}
// namespace kj
c++/src/kj/io.c++
View file @
59267d01
...
...
@@ -271,9 +271,9 @@ ArrayPtr<byte> ArrayOutputStream::getWriteBuffer() {
}
void
ArrayOutputStream
::
write
(
const
void
*
src
,
size_t
size
)
{
if
(
src
==
fillPos
)
{
if
(
src
==
fillPos
&&
fillPos
!=
array
.
end
()
)
{
// Oh goody, the caller wrote directly into our buffer.
KJ_REQUIRE
(
size
<=
array
.
end
()
-
fillPos
);
KJ_REQUIRE
(
size
<=
array
.
end
()
-
fillPos
,
size
,
fillPos
,
array
.
end
()
-
fillPos
);
fillPos
+=
size
;
}
else
{
KJ_REQUIRE
(
size
<=
(
size_t
)(
array
.
end
()
-
fillPos
),
...
...
@@ -299,9 +299,9 @@ ArrayPtr<byte> VectorOutputStream::getWriteBuffer() {
}
void
VectorOutputStream
::
write
(
const
void
*
src
,
size_t
size
)
{
if
(
src
==
fillPos
)
{
if
(
src
==
fillPos
&&
fillPos
!=
vector
.
end
()
)
{
// Oh goody, the caller wrote directly into our buffer.
KJ_REQUIRE
(
size
<=
vector
.
end
()
-
fillPos
);
KJ_REQUIRE
(
size
<=
vector
.
end
()
-
fillPos
,
size
,
fillPos
,
vector
.
end
()
-
fillPos
);
fillPos
+=
size
;
}
else
{
if
(
vector
.
end
()
-
fillPos
<
size
)
{
...
...
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