summaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@oath.com>2018-07-25 14:24:21 +0000
committerTor Brede Vekterli <vekterli@oath.com>2018-07-25 14:24:21 +0000
commit12c8f3005e202b31a8e0ff3816ce9d714a269046 (patch)
treea5d9ba0eedc49df2cea2dbdfea677c4c37ed3775 /staging_vespalib
parente3af3d215feb1e416b27b92bbf421dde281f3a09 (diff)
Remove stringref::c_str()
The expected semantics of c_str() (a null-terminated string) cannot be satisfied with a string reference, so remove the function entirely to prevent people from using it in buggy ways. Replaces c_str() with data() in places where it is presumed safe, otherwise constructs temporary string instances. Certain callsites have been de-stringref'd in favor of regular strings, in particular where C APIs have been transitively called. The vast majority of these were called with string parameters anyway, so should not cause much extra allocation.
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp6
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp2
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp4
3 files changed, 6 insertions, 6 deletions
diff --git a/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp b/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp
index f6427f8acd2..7d047e36566 100644
--- a/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp
+++ b/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp
@@ -40,20 +40,20 @@ MemoryDataStoreTest::testVariableSizeVector()
for (size_t i(0); i < 10000; i++) {
asciistream os;
os << i;
- v.push_back(os.str().c_str(), os.str().size());
+ v.push_back(os.str().data(), os.str().size());
}
for (size_t i(0); i < v.size(); i++) {
asciistream os;
os << i;
EXPECT_EQUAL(os.str().size(), v[i].size());
- EXPECT_EQUAL(0, memcmp(os.str().c_str(), v[i].data(), os.str().size()));
+ EXPECT_EQUAL(0, memcmp(os.str().data(), v[i].data(), os.str().size()));
}
size_t i(0);
for (auto it(v.begin()), mt(v.end()); it != mt; it++, i++) {
asciistream os;
os << i;
EXPECT_EQUAL(os.str().size(), it->size());
- EXPECT_EQUAL(0, memcmp(os.str().c_str(), (*it).data(), os.str().size()));
+ EXPECT_EQUAL(0, memcmp(os.str().data(), (*it).data(), os.str().size()));
}
}
diff --git a/staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp b/staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp
index 53875fe7241..22064864b22 100644
--- a/staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp
+++ b/staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp
@@ -72,7 +72,7 @@ void
GrowableByteBuffer::putString(const vespalib::stringref& v)
{
putInt(v.size());
- putBytes(v.c_str(), v.size());
+ putBytes(v.data(), v.size());
}
void
diff --git a/staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp b/staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp
index ebeda4f1b8b..0ad52f9aac2 100644
--- a/staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp
+++ b/staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp
@@ -177,7 +177,7 @@ JSONWriter::appendKey(const vespalib::stringref & str)
{
considerComma();
indent();
- quote(str.c_str(), str.size());
+ quote(str.data(), str.size());
(*_os) << ':';
_comma = false;
return *this;
@@ -246,7 +246,7 @@ JSONWriter &
JSONWriter::appendString(const vespalib::stringref & str)
{
considerComma();
- quote(str.c_str(), str.size());
+ quote(str.data(), str.size());
updateCommaState();
return *this;
}