0

Convert narrowing casts from T{} to static_cast<T>(): device/

The style guide encourages use of T{}-style casts under the assumption
that the compiler will warn about narrowing.  This warning is currently
disabled; enabling it requires fixing up the cases that narrow.

Bug: 1216696
Change-Id: I5d3c1138bde50bb9931d5e72b462030b4c5ea758
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2946382
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#890227}
This commit is contained in:
Peter Kasting
2021-06-08 13:41:19 +00:00
committed by Chromium LUCI CQ
parent 13aaff80c2
commit c152d0263f
3 changed files with 8 additions and 8 deletions

@ -19,7 +19,7 @@ void RecordConnectedGamepad(GamepadId gamepad_id) {
auto gamepad_id_as_underlying_type =
static_cast<std::underlying_type<GamepadId>::type>(gamepad_id);
base::UmaHistogramSparse("Gamepad.KnownGamepadConnectedWithId",
int32_t{gamepad_id_as_underlying_type});
static_cast<int32_t>(gamepad_id_as_underlying_type));
}
void RecordUnknownGamepad(GamepadSource source) {

@ -1554,7 +1554,7 @@ void NintendoController::SubCommand(uint8_t sub_command,
// Serial subcommands also carry vibration data. Configure the vibration
// portion of the report for a neutral vibration effect (zero amplitude).
// https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/bluetooth_hid_notes.md#output-0x12
report_bytes[0] = uint8_t{output_report_counter_++ & 0xff};
report_bytes[0] = static_cast<uint8_t>(output_report_counter_++ & 0xff);
report_bytes[1] = 0x00;
report_bytes[2] = 0x01;
report_bytes[3] = 0x40;
@ -1608,7 +1608,7 @@ void NintendoController::RequestVibration(double left_frequency,
FrequencyToHex(left_frequency, left_magnitude, &lhf, &llf, &lhfa, &llfa);
FrequencyToHex(right_frequency, right_magnitude, &rhf, &rlf, &rhfa, &rlfa);
std::vector<uint8_t> report_bytes(output_report_size_bytes_ - 1);
uint8_t counter = uint8_t{output_report_counter_++ & 0x0f};
uint8_t counter = static_cast<uint8_t>(output_report_counter_++ & 0x0f);
report_bytes[0] = counter;
report_bytes[1] = lhf & 0xff;
report_bytes[2] = lhfa + ((lhf >> 8) & 0xff);
@ -1698,8 +1698,8 @@ void NintendoController::ReadSpi(uint16_t address, size_t length) {
length = std::min(length, output_report_size_bytes_ - kSpiDataOffset);
uint8_t address_high = (address >> 8) & 0xff;
uint8_t address_low = address & 0xff;
SubCommand(kSubCommandReadSpi,
{address_low, address_high, 0x00, 0x00, uint8_t{length}});
SubCommand(kSubCommandReadSpi, {address_low, address_high, 0x00, 0x00,
static_cast<uint8_t>(length)});
}
void NintendoController::RequestImuCalibration() {

@ -160,7 +160,7 @@ void RawInputGamepadDeviceWin::UpdateGamepad(RAWINPUT* input) {
uint16_t usage_page = usages[j].UsagePage;
uint16_t usage = usages[j].Usage;
if (usage_page == kButtonUsagePage && usage > 0) {
size_t button_index = size_t{usage - 1};
size_t button_index = static_cast<size_t>(usage - 1);
if (button_index < Gamepad::kButtonsLengthCap)
buttons_[button_index] = true;
} else if (usage_page != kButtonUsagePage &&
@ -416,8 +416,8 @@ void RawInputGamepadDeviceWin::QueryNormalButtonCapabilities(
uint16_t usage_max = item.Range.UsageMax;
if (usage_min == 0 || usage_max == 0)
continue;
size_t button_index_min = size_t{usage_min - 1};
size_t button_index_max = size_t{usage_max - 1};
size_t button_index_min = static_cast<size_t>(usage_min - 1);
size_t button_index_max = static_cast<size_t>(usage_max - 1);
if (item.UsagePage == kButtonUsagePage &&
button_index_min < Gamepad::kButtonsLengthCap) {
button_index_max =