Cleanups: casting and typos
- Use static_cast instead of primitive type constructors (more explicit).
- Typo: additiona_info -> additional_info
- Fix filename in Generated by lines for some templates.
- Don't use the slighty silly std::vector<uint8_t>::index_type.
Change-Id: I191282a2daf425b646d5997f621389dba6859de6
diff --git a/DEPS b/DEPS
index 0e646e4..fe823ba 100644
--- a/DEPS
+++ b/DEPS
@@ -1,7 +1,13 @@
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-
+#
+# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+# ! DO NOT ROLL THIS FILE INTO CHROMIUM (or other repositories). !
+# ! It's only useful for the standalone configuration in !
+# ! https://chromium.googlesource.com/deps/inspector_protocol/ !
+# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+#
# This file configures gclient, a tool that installs dependencies
# at particular versions into this source tree. See
# https://chromium.googlesource.com/chromium/tools/depot_tools.git
diff --git a/encoding/cbor.cc b/encoding/cbor.cc
index 07b275c..00cabac 100644
--- a/encoding/cbor.cc
+++ b/encoding/cbor.cc
@@ -34,7 +34,7 @@
// Encodes the initial byte, consisting of the |type| in the first 3 bits
// followed by 5 bits of |additional_info|.
constexpr uint8_t EncodeInitialByte(MajorType type, uint8_t additional_info) {
- return (uint8_t(type) << kMajorTypeBitShift) |
+ return (static_cast<uint8_t>(type) << kMajorTypeBitShift) |
(additional_info & kAdditionalInformationMask);
}
@@ -116,7 +116,7 @@
if (value < 24) {
// Values 0-23 are encoded directly into the additional info of the
// initial byte.
- encoded->push_back(EncodeInitialByte(type, /*additiona_info=*/value));
+ encoded->push_back(EncodeInitialByte(type, /*additional_info=*/value));
return;
}
if (value <= std::numeric_limits<uint8_t>::max()) {
@@ -150,9 +150,9 @@
// See also: https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html
template <typename T>
T ReadBytesMostSignificantByteFirst(span<uint8_t> in) {
- assert(size_t(in.size()) >= sizeof(T));
+ assert(static_cast<std::size_t>(in.size()) >= sizeof(T));
T result = 0;
- for (size_t shift_bytes = 0; shift_bytes < sizeof(T); ++shift_bytes)
+ for (std::size_t shift_bytes = 0; shift_bytes < sizeof(T); ++shift_bytes)
result |= T(in[sizeof(T) - 1 - shift_bytes]) << (shift_bytes * 8);
return result;
}
@@ -179,19 +179,22 @@
}
if (additional_information == kAdditionalInformation2Bytes) {
// Values 256-65535: 1 initial byte + 2 bytes payload.
- if (static_cast<size_t>(bytes.size()) < 1 + sizeof(uint16_t)) return -1;
+ if (static_cast<std::size_t>(bytes.size()) < 1 + sizeof(uint16_t))
+ return -1;
*value = ReadBytesMostSignificantByteFirst<uint16_t>(bytes.subspan(1));
return 3;
}
if (additional_information == kAdditionalInformation4Bytes) {
// 32 bit uint: 1 initial byte + 4 bytes payload.
- if (static_cast<size_t>(bytes.size()) < 1 + sizeof(uint32_t)) return -1;
+ if (static_cast<std::size_t>(bytes.size()) < 1 + sizeof(uint32_t))
+ return -1;
*value = ReadBytesMostSignificantByteFirst<uint32_t>(bytes.subspan(1));
return 5;
}
if (additional_information == kAdditionalInformation8Bytes) {
// 64 bit uint: 1 initial byte + 8 bytes payload.
- if (static_cast<size_t>(bytes.size()) < 1 + sizeof(uint64_t)) return -1;
+ if (static_cast<std::size_t>(bytes.size()) < 1 + sizeof(uint64_t))
+ return -1;
*value = ReadBytesMostSignificantByteFirst<uint64_t>(bytes.subspan(1));
return 9;
}
@@ -663,7 +666,8 @@
SetError(Error::CBOR_INVALID_BINARY);
return;
}
- SetToken(CBORTokenTag::BINARY, std::ptrdiff_t(token_byte_length));
+ SetToken(CBORTokenTag::BINARY,
+ static_cast<std::ptrdiff_t>(token_byte_length));
return;
}
case kInitialByteForDouble: { // DOUBLE
@@ -690,7 +694,7 @@
// Make sure the payload is contained within the message.
if (token_start_internal_value_ + kEncodedEnvelopeHeaderSize +
status_.pos >
- size_t(bytes_.size())) {
+ static_cast<std::size_t>(bytes_.size())) {
SetError(Error::CBOR_INVALID_ENVELOPE);
return;
}
@@ -725,8 +729,8 @@
SetToken(CBORTokenTag::INT32, token_start_length);
return;
case MajorType::STRING: { // STRING8.
- if (!success ||
- remainder.size() < int64_t(token_start_internal_value_)) {
+ if (!success || remainder.size() < static_cast<int64_t>(
+ token_start_internal_value_)) {
SetError(Error::CBOR_INVALID_STRING8);
return;
}
@@ -736,7 +740,8 @@
}
case MajorType::BYTE_STRING: { // STRING16.
if (!success ||
- remainder.size() < int64_t(token_start_internal_value_) ||
+ remainder.size() <
+ static_cast<int64_t>(token_start_internal_value_) ||
// Must be divisible by 2 since UTF16 is 2 bytes per character.
token_start_internal_value_ & 1) {
SetError(Error::CBOR_INVALID_STRING16);
diff --git a/encoding/cbor.h b/encoding/cbor.h
index 4cd567f..b1657d1 100644
--- a/encoding/cbor.h
+++ b/encoding/cbor.h
@@ -82,7 +82,7 @@
bool EncodeStop(std::vector<uint8_t>* out);
private:
- std::vector<uint8_t>::size_type byte_size_pos_ = 0;
+ std::size_t byte_size_pos_ = 0;
};
// This can be used to convert from JSON to CBOR, by passing the
diff --git a/encoding/cbor_test.cc b/encoding/cbor_test.cc
index a71daad..77cd61b 100644
--- a/encoding/cbor_test.cc
+++ b/encoding/cbor_test.cc
@@ -60,7 +60,8 @@
// 500 is encoded as a uint16 after the initial byte.
std::vector<uint8_t> encoded;
EncodeInt32(500, &encoded);
- EXPECT_EQ(size_t(3), encoded.size()); // 1 for initial byte, 2 for uint16.
+ // 1 for initial byte, 2 for uint16.
+ EXPECT_EQ(static_cast<std::size_t>(3), encoded.size());
// first three bits: major type = 0;
// remaining five bits: additional info = 25, indicating payload is uint16.
EXPECT_EQ(25, encoded[0]);
@@ -192,7 +193,7 @@
// CBORTokenizer.
std::vector<uint8_t> encoded;
EncodeString16(span<uint16_t>(), &encoded);
- EXPECT_EQ(size_t(1), encoded.size());
+ EXPECT_EQ(static_cast<std::size_t>(1), encoded.size());
// first three bits: major type = 2; remaining five bits: additional info =
// size 0.
EXPECT_EQ(2 << 5, encoded[0]);
@@ -261,7 +262,7 @@
for (uint16_t ii = 0; ii < 250; ++ii) two_fifty.push_back(ii);
std::vector<uint8_t> encoded;
EncodeString16(span<uint16_t>(two_fifty.data(), two_fifty.size()), &encoded);
- EXPECT_EQ(size_t(3 + 250 * 2), encoded.size());
+ EXPECT_EQ(static_cast<std::size_t>(3 + 250 * 2), encoded.size());
// Now check the first three bytes:
// Major type: 2 (BYTE_STRING)
// Additional information: 25, indicating size is represented by 2 bytes.
@@ -637,7 +638,7 @@
NewJSONWriter(GetLinuxDevPlatform(), &out, &status);
ParseCBOR(span<uint8_t>(bytes.data(), bytes.size()), json_writer.get());
EXPECT_EQ(Error::CBOR_UNEXPECTED_EOF_EXPECTED_VALUE, status.error);
- EXPECT_EQ(int64_t(bytes.size()), status.pos);
+ EXPECT_EQ(static_cast<int64_t>(bytes.size()), status.pos);
EXPECT_EQ("", out);
}
@@ -655,7 +656,7 @@
NewJSONWriter(GetLinuxDevPlatform(), &out, &status);
ParseCBOR(span<uint8_t>(bytes.data(), bytes.size()), json_writer.get());
EXPECT_EQ(Error::CBOR_UNEXPECTED_EOF_IN_ARRAY, status.error);
- EXPECT_EQ(int64_t(bytes.size()), status.pos);
+ EXPECT_EQ(static_cast<int64_t>(bytes.size()), status.pos);
EXPECT_EQ("", out);
}
@@ -737,7 +738,7 @@
// the second envelope start.
std::vector<uint8_t> small_example = MakeNestedCBOR(3);
int64_t opening_segment_size = 1; // Start after the first envelope start.
- while (opening_segment_size < int64_t(small_example.size()) &&
+ while (opening_segment_size < static_cast<int64_t>(small_example.size()) &&
small_example[opening_segment_size] != 0xd8)
opening_segment_size++;
diff --git a/encoding/json_parser.cc b/encoding/json_parser.cc
index 82bd184..e1feffd 100644
--- a/encoding/json_parser.cc
+++ b/encoding/json_parser.cc
@@ -39,7 +39,7 @@
JsonParser(const Platform* platform, JSONParserHandler* handler)
: platform_(platform), handler_(handler) {}
- void Parse(const Char* start, size_t length) {
+ void Parse(const Char* start, std::size_t length) {
start_pos_ = start;
const Char* end = start + length;
const Char* tokenEnd;
@@ -50,10 +50,11 @@
}
private:
- bool CharsToDouble(const uint16_t* chars, size_t length, double* result) {
+ bool CharsToDouble(const uint16_t* chars, std::size_t length,
+ double* result) {
std::string buffer;
buffer.reserve(length + 1);
- for (size_t ii = 0; ii < length; ++ii) {
+ for (std::size_t ii = 0; ii < length; ++ii) {
bool is_ascii = !(chars[ii] & ~0x7F);
if (!is_ascii) return false;
buffer.push_back(static_cast<char>(chars[ii]));
@@ -61,7 +62,7 @@
return platform_->StrToD(buffer.c_str(), result);
}
- bool CharsToDouble(const uint8_t* chars, size_t length, double* result) {
+ bool CharsToDouble(const uint8_t* chars, std::size_t length, double* result) {
std::string buffer(reinterpret_cast<const char*>(chars), length);
return platform_->StrToD(buffer.c_str(), result);
}
diff --git a/encoding/json_parser_test.cc b/encoding/json_parser_test.cc
index 38b0826..babb326 100644
--- a/encoding/json_parser_test.cc
+++ b/encoding/json_parser_test.cc
@@ -248,7 +248,8 @@
exceeded.size()),
&log_);
EXPECT_EQ(Error::JSON_PARSER_STACK_LIMIT_EXCEEDED, log_.status().error);
- EXPECT_EQ(int64_t(strlen("{\"foo\":") * 1001), log_.status().pos);
+ EXPECT_EQ(static_cast<std::ptrdiff_t>(strlen("{\"foo\":") * 1001),
+ log_.status().pos);
// Now way past the limit. Still, the point of exceeding is 1001.
log_ = Log();
std::string far_out = MakeNestedJson(10000);
@@ -257,7 +258,8 @@
far_out.size()),
&log_);
EXPECT_EQ(Error::JSON_PARSER_STACK_LIMIT_EXCEEDED, log_.status().error);
- EXPECT_EQ(int64_t(strlen("{\"foo\":") * 1001), log_.status().pos);
+ EXPECT_EQ(static_cast<std::ptrdiff_t>(strlen("{\"foo\":") * 1001),
+ log_.status().pos);
}
TEST_F(JsonParserTest, NoInputError) {
diff --git a/encoding/json_std_string_writer.cc b/encoding/json_std_string_writer.cc
index c819ff5..5f5ed78 100644
--- a/encoding/json_std_string_writer.cc
+++ b/encoding/json_std_string_writer.cc
@@ -53,7 +53,7 @@
// The following three cases are based on the tables in the example
// section in https://en.wikipedia.org/wiki/Base64. We process three
// input bytes at a time, emitting 4 output bytes at a time.
- size_t ii = 0;
+ std::size_t ii = 0;
// While possible, process three input bytes.
for (; ii + 3 <= in.size(); ii += 3) {
diff --git a/encoding/str_util.cc b/encoding/str_util.cc
index e4e2043..1f4be7c 100644
--- a/encoding/str_util.cc
+++ b/encoding/str_util.cc
@@ -13,7 +13,8 @@
}
bool StrEq(span<uint8_t> left, const char* null_terminated_right) {
- return size_t(left.size()) == strlen(null_terminated_right) &&
+ return static_cast<std::size_t>(left.size()) ==
+ strlen(null_terminated_right) &&
0 == memcmp(left.data(), null_terminated_right, left.size());
}
} // namespace inspector_protocol
diff --git a/lib/base_string_adapter_cc.template b/lib/base_string_adapter_cc.template
index 5ce0f68..b518e80 100644
--- a/lib/base_string_adapter_cc.template
+++ b/lib/base_string_adapter_cc.template
@@ -1,4 +1,4 @@
-// This file is generated by DispatcherBase_cpp.template.
+// This file is generated by base_string_adapter_cc.template.
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
diff --git a/lib/base_string_adapter_h.template b/lib/base_string_adapter_h.template
index 0c57998..37f5f2a 100644
--- a/lib/base_string_adapter_h.template
+++ b/lib/base_string_adapter_h.template
@@ -1,4 +1,4 @@
-// This file is generated by Parser_h.template.
+// This file is generated by base_string_adapter_h.template.
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be