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
d067d620
Commit
d067d620
authored
Oct 14, 2017
by
Kenton Varda
Committed by
GitHub
Oct 14, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #567 from ecatmur/memcpy-null-src
Memcpy null src
parents
2803eb52
886cc3c4
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
30 additions
and
15 deletions
+30
-15
layout.c++
c++/src/capnp/layout.c++
+10
-10
serialize-packed-test.c++
c++/src/capnp/serialize-packed-test.c++
+3
-1
array.h
c++/src/kj/array.h
+6
-2
char.h
c++/src/kj/parse/char.h
+1
-0
string-test.c++
c++/src/kj/string-test.c++
+6
-0
string.c++
c++/src/kj/string.c++
+3
-1
string.h
c++/src/kj/string.h
+1
-1
No files found.
c++/src/capnp/layout.c++
View file @
d067d620
...
...
@@ -371,15 +371,15 @@ struct WireHelpers {
#endif
static
KJ_ALWAYS_INLINE
(
void
zeroMemory
(
byte
*
ptr
,
ByteCount32
count
))
{
memset
(
ptr
,
0
,
unbound
(
count
/
BYTES
));
if
(
count
!=
0u
)
memset
(
ptr
,
0
,
unbound
(
count
/
BYTES
));
}
static
KJ_ALWAYS_INLINE
(
void
zeroMemory
(
word
*
ptr
,
WordCountN
<
29
>
count
))
{
memset
(
ptr
,
0
,
unbound
(
count
*
BYTES_PER_WORD
/
BYTES
));
if
(
count
!=
0u
)
memset
(
ptr
,
0
,
unbound
(
count
*
BYTES_PER_WORD
/
BYTES
));
}
static
KJ_ALWAYS_INLINE
(
void
zeroMemory
(
WirePointer
*
ptr
,
WirePointerCountN
<
29
>
count
))
{
memset
(
ptr
,
0
,
unbound
(
count
*
BYTES_PER_POINTER
/
BYTES
));
if
(
count
!=
0u
)
memset
(
ptr
,
0
,
unbound
(
count
*
BYTES_PER_POINTER
/
BYTES
));
}
static
KJ_ALWAYS_INLINE
(
void
zeroMemory
(
WirePointer
*
ptr
))
{
...
...
@@ -388,20 +388,20 @@ struct WireHelpers {
template
<
typename
T
>
static
inline
void
zeroMemory
(
kj
::
ArrayPtr
<
T
>
array
)
{
memset
(
array
.
begin
(),
0
,
array
.
size
()
*
sizeof
(
array
[
0
]));
if
(
array
.
size
()
!=
0u
)
memset
(
array
.
begin
(),
0
,
array
.
size
()
*
sizeof
(
array
[
0
]));
}
static
KJ_ALWAYS_INLINE
(
void
copyMemory
(
byte
*
to
,
const
byte
*
from
,
ByteCount32
count
))
{
memcpy
(
to
,
from
,
unbound
(
count
/
BYTES
));
if
(
count
!=
0u
)
memcpy
(
to
,
from
,
unbound
(
count
/
BYTES
));
}
static
KJ_ALWAYS_INLINE
(
void
copyMemory
(
word
*
to
,
const
word
*
from
,
WordCountN
<
29
>
count
))
{
memcpy
(
to
,
from
,
unbound
(
count
*
BYTES_PER_WORD
/
BYTES
));
if
(
count
!=
0u
)
memcpy
(
to
,
from
,
unbound
(
count
*
BYTES_PER_WORD
/
BYTES
));
}
static
KJ_ALWAYS_INLINE
(
void
copyMemory
(
WirePointer
*
to
,
const
WirePointer
*
from
,
WirePointerCountN
<
29
>
count
))
{
memcpy
(
to
,
from
,
unbound
(
count
*
BYTES_PER_POINTER
/
BYTES
));
if
(
count
!=
0u
)
memcpy
(
to
,
from
,
unbound
(
count
*
BYTES_PER_POINTER
/
BYTES
));
}
template
<
typename
T
>
...
...
@@ -412,14 +412,14 @@ struct WireHelpers {
// TODO(cleanup): Turn these into a .copyTo() method of ArrayPtr?
template
<
typename
T
>
static
inline
void
copyMemory
(
T
*
to
,
kj
::
ArrayPtr
<
T
>
from
)
{
memcpy
(
to
,
from
.
begin
(),
from
.
size
()
*
sizeof
(
from
[
0
]));
if
(
from
.
size
()
!=
0u
)
memcpy
(
to
,
from
.
begin
(),
from
.
size
()
*
sizeof
(
from
[
0
]));
}
template
<
typename
T
>
static
inline
void
copyMemory
(
T
*
to
,
kj
::
ArrayPtr
<
const
T
>
from
)
{
memcpy
(
to
,
from
.
begin
(),
from
.
size
()
*
sizeof
(
from
[
0
]));
if
(
from
.
size
()
!=
0u
)
memcpy
(
to
,
from
.
begin
(),
from
.
size
()
*
sizeof
(
from
[
0
]));
}
static
KJ_ALWAYS_INLINE
(
void
copyMemory
(
char
*
to
,
kj
::
StringPtr
from
))
{
memcpy
(
to
,
from
.
begin
(),
from
.
size
()
*
sizeof
(
from
[
0
]));
if
(
from
.
size
()
!=
0u
)
memcpy
(
to
,
from
.
begin
(),
from
.
size
()
*
sizeof
(
from
[
0
]));
}
static
KJ_ALWAYS_INLINE
(
bool
boundsCheck
(
...
...
c++/src/capnp/serialize-packed-test.c++
View file @
d067d620
...
...
@@ -94,7 +94,9 @@ void expectPacksTo(kj::ArrayPtr<const byte> unpackedUnaligned, kj::ArrayPtr<cons
// Make a guaranteed-to-be-aligned copy of the unpacked buffer.
kj
::
Array
<
word
>
unpackedWords
=
kj
::
heapArray
<
word
>
(
unpackedSizeInWords
);
memcpy
(
unpackedWords
.
begin
(),
unpackedUnaligned
.
begin
(),
unpackedUnaligned
.
size
());
if
(
unpackedUnaligned
.
size
()
!=
0u
)
{
memcpy
(
unpackedWords
.
begin
(),
unpackedUnaligned
.
begin
(),
unpackedUnaligned
.
size
());
}
kj
::
ArrayPtr
<
const
byte
>
unpacked
=
unpackedWords
.
asBytes
();
// -----------------------------------------------------------------
...
...
c++/src/kj/array.h
View file @
d067d620
...
...
@@ -682,7 +682,9 @@ struct CopyConstructArray_;
template
<
typename
T
,
bool
move
>
struct
CopyConstructArray_
<
T
,
T
*
,
move
,
true
>
{
static
inline
T
*
apply
(
T
*
__restrict__
pos
,
T
*
start
,
T
*
end
)
{
memcpy
(
pos
,
start
,
reinterpret_cast
<
byte
*>
(
end
)
-
reinterpret_cast
<
byte
*>
(
start
));
if
(
end
!=
start
)
{
memcpy
(
pos
,
start
,
reinterpret_cast
<
byte
*>
(
end
)
-
reinterpret_cast
<
byte
*>
(
start
));
}
return
pos
+
(
end
-
start
);
}
};
...
...
@@ -690,7 +692,9 @@ struct CopyConstructArray_<T, T*, move, true> {
template
<
typename
T
>
struct
CopyConstructArray_
<
T
,
const
T
*
,
false
,
true
>
{
static
inline
T
*
apply
(
T
*
__restrict__
pos
,
const
T
*
start
,
const
T
*
end
)
{
memcpy
(
pos
,
start
,
reinterpret_cast
<
const
byte
*>
(
end
)
-
reinterpret_cast
<
const
byte
*>
(
start
));
if
(
end
!=
start
)
{
memcpy
(
pos
,
start
,
reinterpret_cast
<
const
byte
*>
(
end
)
-
reinterpret_cast
<
const
byte
*>
(
start
));
}
return
pos
+
(
end
-
start
);
}
};
...
...
c++/src/kj/parse/char.h
View file @
d067d620
...
...
@@ -219,6 +219,7 @@ namespace _ { // private
struct
IdentifierToString
{
inline
String
operator
()(
char
first
,
const
Array
<
char
>&
rest
)
const
{
if
(
rest
.
size
()
==
0
)
return
heapString
(
&
first
,
1
);
String
result
=
heapString
(
rest
.
size
()
+
1
);
result
[
0
]
=
first
;
memcpy
(
result
.
begin
()
+
1
,
rest
.
begin
(),
rest
.
size
());
...
...
c++/src/kj/string-test.c++
View file @
d067d620
...
...
@@ -54,6 +54,12 @@ TEST(String, Str) {
EXPECT_EQ
(
"foo"
,
str
(
mv
(
f
)));
}
TEST
(
String
,
Nullptr
)
{
EXPECT_EQ
(
String
(
nullptr
),
""
);
EXPECT_EQ
(
StringPtr
(
String
(
nullptr
)).
size
(),
0u
);
EXPECT_EQ
(
StringPtr
(
String
(
nullptr
))[
0
],
'\0'
);
}
TEST
(
String
,
StartsEndsWith
)
{
EXPECT_TRUE
(
StringPtr
(
"foobar"
).
startsWith
(
"foo"
));
EXPECT_FALSE
(
StringPtr
(
"foobar"
).
startsWith
(
"bar"
));
...
...
c++/src/kj/string.c++
View file @
d067d620
...
...
@@ -111,7 +111,9 @@ String heapString(size_t size) {
String
heapString
(
const
char
*
value
,
size_t
size
)
{
char
*
buffer
=
_
::
HeapArrayDisposer
::
allocate
<
char
>
(
size
+
1
);
memcpy
(
buffer
,
value
,
size
);
if
(
size
!=
0u
)
{
memcpy
(
buffer
,
value
,
size
);
}
buffer
[
size
]
=
'\0'
;
return
String
(
buffer
,
size
,
_
::
HeapArrayDisposer
::
instance
);
}
...
...
c++/src/kj/string.h
View file @
d067d620
...
...
@@ -445,7 +445,7 @@ inline String Stringifier::operator*(const Array<T>& arr) const {
// =======================================================================================
// Inline implementation details.
inline
StringPtr
::
StringPtr
(
const
String
&
value
)
:
content
(
value
.
begin
(),
value
.
size
()
+
1
)
{}
inline
StringPtr
::
StringPtr
(
const
String
&
value
)
:
content
(
value
.
cStr
(),
value
.
size
()
+
1
)
{}
inline
constexpr
StringPtr
::
operator
ArrayPtr
<
const
char
>
()
const
{
return
ArrayPtr
<
const
char
>
(
content
.
begin
(),
content
.
size
()
-
1
);
...
...
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