aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kasting <pkasting@chromium.org>2021-06-09 19:27:03 +0000
committerCopybara-Service <copybara-worker@google.com>2021-07-25 21:32:31 -0700
commit3865f0bceb04ae529ba0c2d98a869a16072a90c2 (patch)
treed27353ae58fbb351a7720038358a698ab82706bf
parent1cec5a775590551e3c9f950afad3d95a6f6d950f (diff)
downloadzucchini-3865f0bceb04ae529ba0c2d98a869a16072a90c2.tar.gz
Add explicit type conversions where necessary: components/
These are cases that are implicitly narrowing today, and must do so explicitly in order to enable -Wc++11-narrowing. No behavior change intended. Bug: 1216696 Change-Id: Ic8f194bb0ab9a247d3e84cc59a687285cdb96d48 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2947886 Auto-Submit: Peter Kasting <pkasting@chromium.org> Commit-Queue: Jochen Eisinger <jochen@chromium.org> Reviewed-by: Jochen Eisinger <jochen@chromium.org> Cr-Commit-Position: refs/heads/master@{#890878} NOKEYCHECK=True GitOrigin-RevId: 379c52be13901beae4f773fe9e8054ad42a186c4
-rw-r--r--disassembler_ztf_unittest.cc7
-rw-r--r--image_utils.h4
-rw-r--r--rel32_finder_unittest.cc3
-rw-r--r--reloc_elf_unittest.cc3
-rw-r--r--type_ztf.h6
5 files changed, 14 insertions, 9 deletions
diff --git a/disassembler_ztf_unittest.cc b/disassembler_ztf_unittest.cc
index 515a1e3..9b53e62 100644
--- a/disassembler_ztf_unittest.cc
+++ b/disassembler_ztf_unittest.cc
@@ -373,7 +373,8 @@ TEST(DisassemblerZtfTest, WriteOutOfBoundsRefs) {
{{DisassemblerZtf::kAngles, DisassemblerZtf::kAnglesAbs3},
{Reference({4, 50})}}, // This should fail to write.
{{DisassemblerZtf::kBrackets, DisassemblerZtf::kBracketsRel2},
- {Reference({139, mutable_text.size()})}}, // This should fail.
+ {Reference({139, static_cast<offset_t>(
+ mutable_text.size())})}}, // This should fail.
{{DisassemblerZtf::kParentheses, DisassemblerZtf::kParenthesesAbs1},
{Reference({174, 21})}}, // This should fail.
{{DisassemblerZtf::kBraces, DisassemblerZtf::kBracesAbs1},
@@ -390,8 +391,8 @@ TEST(DisassemblerZtfTest, WriteOutOfBoundsRefs) {
change_map.at({DisassemblerZtf::kAngles, DisassemblerZtf::kAnglesAbs1})
.emplace(Reference{4, 0});
update_map({DisassemblerZtf::kBrackets, DisassemblerZtf::kBracketsRel2},
- Reference({139, mutable_text.size()}), Reference({139, 149}),
- &change_map);
+ Reference({139, static_cast<offset_t>(mutable_text.size())}),
+ Reference({139, 149}), &change_map);
update_map({DisassemblerZtf::kParentheses, DisassemblerZtf::kParenthesesAbs1},
Reference({174, 21}), Reference({174, 4}), &change_map);
ConstBufferView const_image(image);
diff --git a/image_utils.h b/image_utils.h
index 3d4a83a..3bd7a79 100644
--- a/image_utils.h
+++ b/image_utils.h
@@ -176,8 +176,8 @@ constexpr ExecutableType CastToExecutableType(uint32_t possible_exe_type) {
inline std::string CastExecutableTypeToString(ExecutableType exe_type) {
uint32_t v = static_cast<uint32_t>(exe_type);
- char result[] = {v & 0xFF, (v >> 8) & 0xFF, (v >> 16) & 0xFF,
- (v >> 24) & 0xFF, 0};
+ char result[] = {static_cast<char>(v), static_cast<char>(v >> 8),
+ static_cast<char>(v >> 16), static_cast<char>(v >> 24), 0};
return result;
}
diff --git a/rel32_finder_unittest.cc b/rel32_finder_unittest.cc
index 8f274d5..69ea42a 100644
--- a/rel32_finder_unittest.cc
+++ b/rel32_finder_unittest.cc
@@ -132,7 +132,8 @@ class TestRel32Finder : public Rel32Finder {
AddressTranslator GetTrivialTranslator(size_t size) {
AddressTranslator translator;
EXPECT_EQ(AddressTranslator::kSuccess,
- translator.Initialize({{0, size, 0U, size}}));
+ translator.Initialize({{0, static_cast<offset_t>(size), 0U,
+ static_cast<rva_t>(size)}}));
return translator;
}
diff --git a/reloc_elf_unittest.cc b/reloc_elf_unittest.cc
index ac5086a..b03f403 100644
--- a/reloc_elf_unittest.cc
+++ b/reloc_elf_unittest.cc
@@ -61,7 +61,8 @@ class FakeImageWithReloc {
const std::vector<RelocSpec>& reloc_specs)
: image_data_(image_size, 0xFF),
mutable_image_(&image_data_[0], image_data_.size()) {
- translator_.Initialize({{0, image_size, base_rva, image_size}});
+ translator_.Initialize({{0, static_cast<offset_t>(image_size), base_rva,
+ static_cast<rva_t>(image_size)}});
// Set up test image with reloc sections.
for (const RelocSpec& reloc_spec : reloc_specs) {
BufferRegion reloc_region = {reloc_spec.start, reloc_spec.data.size()};
diff --git a/type_ztf.h b/type_ztf.h
index 42798b2..8ecc9ca 100644
--- a/type_ztf.h
+++ b/type_ztf.h
@@ -38,11 +38,13 @@ struct DeltaLineCol {
};
constexpr DeltaLineCol operator-(const LineCol& lhs, const LineCol& rhs) {
- return DeltaLineCol{lhs.line - rhs.line, lhs.col - rhs.col};
+ return DeltaLineCol{static_cast<dim_t>(lhs.line - rhs.line),
+ static_cast<dim_t>(lhs.col - rhs.col)};
}
constexpr LineCol operator+(const LineCol& lhs, const DeltaLineCol& rhs) {
- return LineCol{lhs.line + rhs.line, lhs.col + rhs.col};
+ return LineCol{static_cast<dim_t>(lhs.line + rhs.line),
+ static_cast<dim_t>(lhs.col + rhs.col)};
}
} // namespace ztf