summaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@oath.com>2018-07-26 14:03:08 +0200
committerGitHub <noreply@github.com>2018-07-26 14:03:08 +0200
commit8039d52c40c5860ab14030975c728c9a7f458cb4 (patch)
tree12343d0c12a76084f321a7609d4c79fa461c7ad8 /staging_vespalib
parentdf6f72fb34b6d28d6ee27e42ebfba24a4d3545ef (diff)
parent5037bb7c8c9de94337c0d5bc1b831145f69ec9a3 (diff)
Merge pull request #6469 from vespa-engine/vekterli/remove-dangerous-stringref-c_str-function
Remove dangerous stringref::c_str()
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp6
-rw-r--r--staging_vespalib/src/vespa/vespalib/objects/fieldbase.h1
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp2
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp4
4 files changed, 7 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/objects/fieldbase.h b/staging_vespalib/src/vespa/vespalib/objects/fieldbase.h
index cdb9ae95c72..d10687a36ad 100644
--- a/staging_vespalib/src/vespa/vespalib/objects/fieldbase.h
+++ b/staging_vespalib/src/vespa/vespalib/objects/fieldbase.h
@@ -9,6 +9,7 @@ class IFieldBase
{
public:
virtual ~IFieldBase() { }
+ // Overrides must guarantee that returned reference is zero-terminated.
virtual stringref getName() const = 0;
};
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;
}