From 906023076702fbf6518010ae2f2743b5bc32dd18 Mon Sep 17 00:00:00 2001 From: "olafvdspek@gmail.com" Date: Tue, 20 Mar 2012 17:30:24 +0000 Subject: [PATCH] Don't dereference begin() when range is empty --- src/ctemplate/str_ref.h.in | 10 ++++++++-- src/windows/ctemplate/str_ref.h | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/ctemplate/str_ref.h.in b/src/ctemplate/str_ref.h.in index e6dd13e..599c84b 100644 --- a/src/ctemplate/str_ref.h.in +++ b/src/ctemplate/str_ref.h.in @@ -51,7 +51,10 @@ public: template 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() diff --git a/src/windows/ctemplate/str_ref.h b/src/windows/ctemplate/str_ref.h index ff63c23..20a2663 100644 --- a/src/windows/ctemplate/str_ref.h +++ b/src/windows/ctemplate/str_ref.h @@ -56,7 +56,10 @@ public: template 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()