Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(746)

Unified Diff: src/inspector/String16.cpp

Issue 2332163002: [inspector] fixed all shorten-64-to-32 warnings (Closed)
Patch Set: fixed compilation on linux bot Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/inspector/String16.h ('k') | src/inspector/StringUtil.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/inspector/String16.cpp
diff --git a/src/inspector/String16.cpp b/src/inspector/String16.cpp
index e14d19eee7440a8e763b212a6c7ea19142ed63db..d7649a7bb914aa16408ac144180d47c87a6d7b73 100644
--- a/src/inspector/String16.cpp
+++ b/src/inspector/String16.cpp
@@ -11,6 +11,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
+#include <limits>
#include <locale>
#include <string>
@@ -38,9 +39,12 @@ int charactersToInteger(const UChar* characters, size_t length,
buffer.push_back('\0');
char* endptr;
- int result = std::strtol(buffer.data(), &endptr, 10);
- if (ok) *ok = !(*endptr);
- return result;
+ long result = std::strtol(buffer.data(), &endptr, 10);
+ if (ok) {
+ *ok = !(*endptr) && result <= std::numeric_limits<int>::max() &&
+ result >= std::numeric_limits<int>::min();
+ }
+ return static_cast<int>(result);
}
const UChar replacementCharacter = 0xFFFD;
@@ -249,7 +253,7 @@ static const UChar32 offsetsFromUTF8[6] = {0x00000000UL,
static_cast<UChar32>(0xFA082080UL),
static_cast<UChar32>(0x82082080UL)};
-static inline UChar32 readUTF8Sequence(const char*& sequence, unsigned length) {
+static inline UChar32 readUTF8Sequence(const char*& sequence, size_t length) {
UChar32 character = 0;
// The cases all fall through.
@@ -367,6 +371,14 @@ String16 String16::fromInteger(int number) {
}
// static
+String16 String16::fromInteger(size_t number) {
+ const size_t kBufferSize = 50;
+ char buffer[kBufferSize];
+ std::snprintf(buffer, kBufferSize, "%zu", number);
alph 2016/09/13 00:46:48 v8 uses OS::SNPrintF
kozy 2016/09/13 01:00:20 I'll replace it in follow-up.
+ return String16(buffer);
+}
+
+// static
String16 String16::fromDouble(double number) {
const size_t kBufferSize = 100;
char buffer[kBufferSize];
@@ -397,8 +409,8 @@ int String16::toInteger(bool* ok) const {
String16 String16::stripWhiteSpace() const {
if (!length()) return String16();
- unsigned start = 0;
- unsigned end = length() - 1;
+ size_t start = 0;
+ size_t end = length() - 1;
// skip white space from start
while (start <= end && isSpaceOrNewLine(characters16()[start])) ++start;
@@ -456,12 +468,12 @@ String16 String16::fromUTF8(const char* stringStart, size_t length) {
true) != conversionOK)
return String16();
- unsigned utf16Length = bufferCurrent - bufferStart;
+ size_t utf16Length = bufferCurrent - bufferStart;
return String16(bufferStart, utf16Length);
}
std::string String16::utf8() const {
- unsigned length = this->length();
+ size_t length = this->length();
if (!length) return std::string("");
« no previous file with comments | « src/inspector/String16.h ('k') | src/inspector/StringUtil.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698