summaryrefslogtreecommitdiff
path: root/boost/uuid/string_generator.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/uuid/string_generator.hpp')
-rw-r--r--boost/uuid/string_generator.hpp45
1 files changed, 29 insertions, 16 deletions
diff --git a/boost/uuid/string_generator.hpp b/boost/uuid/string_generator.hpp
index 538ebe85dd..b75f166713 100644
--- a/boost/uuid/string_generator.hpp
+++ b/boost/uuid/string_generator.hpp
@@ -32,8 +32,8 @@ namespace uuids {
// and be more efficient
// would like to accept the following forms:
// 0123456789abcdef0123456789abcdef
-// 01234567-89ab-cdef-0123456789abcdef
-// {01234567-89ab-cdef-0123456789abcdef}
+// 01234567-89ab-cdef-0123-456789abcdef
+// {01234567-89ab-cdef-0123-456789abcdef}
// {0123456789abcdef0123456789abcdef}
// others?
struct string_generator {
@@ -81,8 +81,9 @@ struct string_generator {
}
}
- if (has_dashes) {
- if (i == 6 || i == 8 || i == 10) {
+ // if there are dashes, they must be in every slot
+ else if (i == 6 || i == 8 || i == 10) {
+ if (has_dashes == true) {
if (is_dash(c)) {
c = get_next_char(begin, end);
} else {
@@ -90,6 +91,7 @@ struct string_generator {
}
}
}
+
*it_byte = get_value(c);
@@ -103,6 +105,11 @@ struct string_generator {
c = get_next_char(begin, end);
check_close_brace(c, open_brace_char);
}
+
+ // check end of string - any additional data is an invalid uuid
+ if (begin != end) {
+ throw_invalid();
+ }
return u;
}
@@ -118,27 +125,33 @@ private:
}
unsigned char get_value(char c) const {
- static char const*const digits_begin = "0123456789abcdefABCDEF";
- static char const*const digits_end = digits_begin + 22;
+ static char const digits_begin[] = "0123456789abcdefABCDEF";
+ static size_t digits_len = (sizeof(digits_begin) / sizeof(char)) - 1;
+ static char const*const digits_end = digits_begin + digits_len;
static unsigned char const values[] =
- { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,10,11,12,13,14,15
- , static_cast<unsigned char>(-1) };
+ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,10,11,12,13,14,15 };
- char const* d = std::find(digits_begin, digits_end, c);
- return values[d - digits_begin];
+ size_t pos = std::find(digits_begin, digits_end, c) - digits_begin;
+ if (pos >= digits_len) {
+ throw_invalid();
+ }
+ return values[pos];
}
unsigned char get_value(wchar_t c) const {
- static wchar_t const*const digits_begin = L"0123456789abcdefABCDEF";
- static wchar_t const*const digits_end = digits_begin + 22;
+ static wchar_t const digits_begin[] = L"0123456789abcdefABCDEF";
+ static size_t digits_len = (sizeof(digits_begin) / sizeof(wchar_t)) - 1;
+ static wchar_t const*const digits_end = digits_begin + digits_len;
static unsigned char const values[] =
- { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,10,11,12,13,14,15
- , static_cast<unsigned char>(-1) };
+ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,10,11,12,13,14,15 };
- wchar_t const* d = std::find(digits_begin, digits_end, c);
- return values[d - digits_begin];
+ size_t pos = std::find(digits_begin, digits_end, c) - digits_begin;
+ if (pos >= digits_len) {
+ throw_invalid();
+ }
+ return values[pos];
}
bool is_dash(char c) const {