MCPcopy Create free account
hub / github.com/BVLC/caffe / CloneString

Function CloneString

src/gtest/gtest-all.cpp:2138–2147  ·  view source on GitHub ↗

Copies at most length characters from str into a newly-allocated piece of memory of size length+1. The memory is allocated with new[]. A terminating null byte is written to the memory, and a pointer to it is returned. If str is NULL, NULL is returned.

Source from the content-addressed store, hash-verified

2136// A terminating null byte is written to the memory, and a pointer to it
2137// is returned. If str is NULL, NULL is returned.
2138static char* CloneString(const char* str, size_t length) {
2139 if (str == NULL) {
2140 return NULL;
2141 } else {
2142 char* const clone = new char[length + 1];
2143 posix::StrNCpy(clone, str, length);
2144 clone[length] = '\0';
2145 return clone;
2146 }
2147}
2148
2149// Clones a 0-terminated C string, allocating memory using new. The
2150// caller is responsible for deleting[] the return value. Returns the

Callers 1

CloneCStringMethod · 0.85

Calls 1

StrNCpyFunction · 0.85

Tested by

no test coverage detected