Index: include/lldb/Utility/UUID.h =================================================================== --- include/lldb/Utility/UUID.h +++ include/lldb/Utility/UUID.h @@ -85,7 +85,7 @@ //------------------------------------------------------------------ // Classes that inherit from UUID can see and modify these //------------------------------------------------------------------ - uint32_t m_num_uuid_bytes; // Should be 16 or 20 + uint32_t m_num_uuid_bytes; ValueType m_uuid; }; Index: source/Utility/UUID.cpp =================================================================== --- source/Utility/UUID.cpp +++ source/Utility/UUID.cpp @@ -56,22 +56,26 @@ char buf[256]; if (!separator) separator = "-"; - const uint8_t *u = (const uint8_t *)GetBytes(); - if (sizeof(buf) > - (size_t)snprintf(buf, sizeof(buf), "%2.2X%2.2X%2.2X%2.2X%s%2.2X%2.2X%s%2." - "2X%2.2X%s%2.2X%2.2X%s%2.2X%2.2X%2.2X%" - "2.2X%2.2X%2.2X", - u[0], u[1], u[2], u[3], separator, u[4], u[5], separator, - u[6], u[7], separator, u[8], u[9], separator, u[10], - u[11], u[12], u[13], u[14], u[15])) { + auto u = reinterpret_cast(GetBytes()); + int required_bytes; + + required_bytes = + snprintf(buf, sizeof(buf), + "%2.2X%2.2X%2.2X%2.2X%s%2.2X%2.2X%s%2.2X%2.2X%s" + "%2.2X%2.2X%s%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", + u[0], u[1], u[2], u[3], separator, u[4], u[5], separator, u[6], + u[7], separator, u[8], u[9], separator, u[10], u[11], u[12], + u[13], u[14], u[15]); + assert(required_bytes < sizeof(buf)); + result.append(buf); + + if (m_num_uuid_bytes > 16) { + required_bytes = snprintf(buf, sizeof(buf), "%s%2.2X%2.2X%2.2X%2.2X", + separator, u[16], u[17], u[18], u[19]); + assert(required_bytes < sizeof(buf)); result.append(buf); - if (m_num_uuid_bytes == 20) { - if (sizeof(buf) > (size_t)snprintf(buf, sizeof(buf), - "%s%2.2X%2.2X%2.2X%2.2X", separator, - u[16], u[17], u[18], u[19])) - result.append(buf); - } } + return result; } @@ -80,28 +84,16 @@ } bool UUID::SetBytes(const void *uuid_bytes, uint32_t num_uuid_bytes) { - if (uuid_bytes) { - switch (num_uuid_bytes) { - case 20: - m_num_uuid_bytes = 20; - break; - case 16: - m_num_uuid_bytes = 16; - m_uuid[16] = m_uuid[17] = m_uuid[18] = m_uuid[19] = 0; - break; - default: - // Unsupported UUID byte size - m_num_uuid_bytes = 0; - break; - } - - if (m_num_uuid_bytes > 0) { - ::memcpy(m_uuid, uuid_bytes, m_num_uuid_bytes); - return true; - } + if (uuid_bytes == nullptr || num_uuid_bytes == 0) { + m_num_uuid_bytes = 0; + return false; } - ::memset(m_uuid, 0, sizeof(m_uuid)); - return false; + + m_num_uuid_bytes = num_uuid_bytes; + ::memcpy(m_uuid, uuid_bytes, m_num_uuid_bytes); + ::memset(m_uuid + num_uuid_bytes, 0, sizeof(m_uuid) - m_num_uuid_bytes); + + return true; } size_t UUID::GetByteSize() const { return m_num_uuid_bytes; }