Index: src/utils.h |
diff --git a/src/utils.h b/src/utils.h |
index f4a0598c20368b1ae7e936d43196bd74f8e5f22f..c271ae17f74de8aa33a694641238c62e03aafb61 100644 |
--- a/src/utils.h |
+++ b/src/utils.h |
@@ -66,7 +66,7 @@ static inline intptr_t OffsetFrom(T x) { |
// integral types. |
template <typename T> |
static inline T AddressFrom(intptr_t x) { |
- return static_cast<T>(0) + x; |
+ return static_cast<T>(static_cast<T>(0) + x); |
} |
@@ -137,6 +137,13 @@ static T Min(T a, T b) { |
} |
+inline int StrLength(const char* string) { |
+ size_t length = strlen(string); |
+ ASSERT(length == static_cast<size_t>(static_cast<int>(length))); |
+ return static_cast<int>(length); |
+} |
+ |
+ |
// ---------------------------------------------------------------------------- |
// BitField is a help template for encoding and decode bitfield with |
// unsigned content. |
@@ -449,15 +456,15 @@ class ScopedVector : public Vector<T> { |
inline Vector<const char> CStrVector(const char* data) { |
- return Vector<const char>(data, static_cast<int>(strlen(data))); |
+ return Vector<const char>(data, StrLength(data)); |
} |
inline Vector<char> MutableCStrVector(char* data) { |
- return Vector<char>(data, static_cast<int>(strlen(data))); |
+ return Vector<char>(data, StrLength(data)); |
} |
inline Vector<char> MutableCStrVector(char* data, int max) { |
- int length = static_cast<int>(strlen(data)); |
+ int length = StrLength(data); |
return Vector<char>(data, (length < max) ? length : max); |
} |