1
0
mirror of https://github.com/OlafvdSpek/ctemplate.git synced 2025-09-28 19:05:49 +08:00

Don't dereference begin() when range is empty

This commit is contained in:
olafvdspek@gmail.com 2012-03-20 17:30:24 +00:00
parent 356d7dfac9
commit 9060230767
2 changed files with 16 additions and 4 deletions

View File

@ -51,7 +51,10 @@ public:
template <class U>
str_ref_basic(const U& c)
{
assign(&*c.begin(), c.end() - c.begin() + &*c.begin());
if (c.end() != c.begin())
assign(&*c.begin(), c.end() - c.begin() + &*c.begin());
else
clear();
}
str_ref_basic(const void* b, const void* e)
@ -66,7 +69,10 @@ public:
str_ref_basic(const char* b)
{
assign(b, strlen(b));
if (b)
assign(b, strlen(b));
else
clear();
}
void clear()

View File

@ -56,7 +56,10 @@ public:
template <class U>
str_ref_basic(const U& c)
{
assign(&*c.begin(), c.end() - c.begin() + &*c.begin());
if (c.end() != c.begin())
assign(&*c.begin(), c.end() - c.begin() + &*c.begin());
else
clear();
}
str_ref_basic(const void* b, const void* e)
@ -71,7 +74,10 @@ public:
str_ref_basic(const char* b)
{
assign(b, strlen(b));
if (b)
assign(b, strlen(b));
else
clear();
}
void clear()