Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/coding
diff options
context:
space:
mode:
authorKirill Zhdanovich <kzhdanovich@gmail.com>2013-04-14 15:08:33 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:53:13 +0300
commit8be07b53ac27dbacedee3494dc529010b7ddb611 (patch)
treef7e23c4e4a62664aa742a3836ded5214191bd8c5 /coding
parent6e0846ec57b918022ed5d5a9c8a45e2958e47c2c (diff)
Fix handling of empty strings in ToHex().
Diffstat (limited to 'coding')
-rw-r--r--coding/coding_tests/hex_test.cpp12
-rw-r--r--coding/hex.hpp4
2 files changed, 14 insertions, 2 deletions
diff --git a/coding/coding_tests/hex_test.cpp b/coding/coding_tests/hex_test.cpp
index a0686e3dc0..2ba539687e 100644
--- a/coding/coding_tests/hex_test.cpp
+++ b/coding/coding_tests/hex_test.cpp
@@ -18,7 +18,7 @@ static string GenString()
{
static PseudoRNG32 rng;
string result;
- // By VNG: avoid empty string, else TeHex function failed.
+ // Avoid empty string, since we test it seperately.
size_t size = rng.Generate() % 20 + 1;
for (size_t i = 0; i < size; ++i)
{
@@ -47,3 +47,13 @@ UNIT_TEST(DecodeLowerCaseHex)
{
TEST_EQUAL(FromHex("fe"), "\xfe", ());
}
+
+UNIT_TEST(EncodeEmptyString)
+{
+ TEST_EQUAL(ToHex(string()), "", ());
+}
+
+UNIT_TEST(DecodeEmptyString)
+{
+ TEST_EQUAL(FromHex(""), "", ());
+}
diff --git a/coding/hex.hpp b/coding/hex.hpp
index 22a82af389..86ebe4dda6 100644
--- a/coding/hex.hpp
+++ b/coding/hex.hpp
@@ -27,7 +27,9 @@ template <typename ContainerT>
inline string ToHex(ContainerT const & container)
{
STATIC_ASSERT(sizeof(*container.begin()) == 1);
- ASSERT ( !container.empty(), ("Dereference of container::end() is illegal") );
+
+ if (container.empty())
+ return string();
return ToHex(&*container.begin(), container.end() - container.begin());
}