From b97ddb34fe85bc3e784b92d8c5c4c970f429f012 Mon Sep 17 00:00:00 2001 From: Zhu Yuejun Date: Sun, 15 Jan 2017 14:26:23 +0800 Subject: [PATCH 1/3] Use explicit type conversion --- include/slice.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/slice.h b/include/slice.h index f4c037f..69382ce 100644 --- a/include/slice.h +++ b/include/slice.h @@ -34,12 +34,16 @@ class Slice { // Create a slice that refers to d[0,n-1]. Slice(const char* d, size_t n) : data_(d), size_(n) { } + + Slice(const unsigned char* d, size_t n) : data_(reinterpret(d)), size_(n) { } // Create a slice that refers to the contents of "s" - Slice(const std::string& s) : data_(s.data()), size_(s.size()) { } + Slice(const std::string& s) : data_(s.data()), size_(static_cast(s.size())) { } // Create a slice that refers to s[0,strlen(s)-1] - Slice(const char* s) : data_(s), size_(strlen(s)) { } + Slice(const char* s) : data_(s), size_(static_cast(strlen(s))) { } + + Slice(const unsigned char* s) : data_(reinterpret(s)), size_(static_cast(strlen(s))) { } // Return a pointer to the beginning of the referenced data const char* data() const { return data_; } From 500624b2675092485d2bf205bf34700d09b6cebb Mon Sep 17 00:00:00 2001 From: JayZhu Date: Sun, 15 Jan 2017 05:12:28 -0800 Subject: [PATCH 2/3] modify slice.h --- include/slice.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/slice.h b/include/slice.h index 69382ce..5eb9113 100644 --- a/include/slice.h +++ b/include/slice.h @@ -35,7 +35,7 @@ class Slice { // Create a slice that refers to d[0,n-1]. Slice(const char* d, size_t n) : data_(d), size_(n) { } - Slice(const unsigned char* d, size_t n) : data_(reinterpret(d)), size_(n) { } + Slice(const unsigned char* d, size_t n) : data_(reinterpret_cast(d)), size_(n) { } // Create a slice that refers to the contents of "s" Slice(const std::string& s) : data_(s.data()), size_(static_cast(s.size())) { } @@ -43,7 +43,7 @@ class Slice { // Create a slice that refers to s[0,strlen(s)-1] Slice(const char* s) : data_(s), size_(static_cast(strlen(s))) { } - Slice(const unsigned char* s) : data_(reinterpret(s)), size_(static_cast(strlen(s))) { } + Slice(const unsigned char* s) : data_(reinterpret_cast(s)), size_(strlen(reinterpret_cast(s))) { } // Return a pointer to the beginning of the referenced data const char* data() const { return data_; } From a745358b961fc3c2a1972036c51f43afe0c539e1 Mon Sep 17 00:00:00 2001 From: JayZhu Date: Sun, 15 Jan 2017 05:14:50 -0800 Subject: [PATCH 3/3] modify slice.h -> add const unsigned char* --- include/slice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/slice.h b/include/slice.h index 5eb9113..8ff8eb7 100644 --- a/include/slice.h +++ b/include/slice.h @@ -41,7 +41,7 @@ class Slice { Slice(const std::string& s) : data_(s.data()), size_(static_cast(s.size())) { } // Create a slice that refers to s[0,strlen(s)-1] - Slice(const char* s) : data_(s), size_(static_cast(strlen(s))) { } + Slice(const char* s) : data_(s), size_(strlen(s)) { } Slice(const unsigned char* s) : data_(reinterpret_cast(s)), size_(strlen(reinterpret_cast(s))) { }