mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 19:54:57 +08:00
use static casts rather than C-style casting
C-style casting can result in undesired reinterpret_casts So we should avoid them, see: http://stackoverflow.com/questions/332030/when-should-static-cast-dynamic-cast-and-reinterpret-cast-be-used
This commit is contained in:
parent
3f2ed36849
commit
cfac5bbcc9
@ -60,8 +60,8 @@ MillisecondTimer::MillisecondTimer (const uint32_t millis)
|
|||||||
{
|
{
|
||||||
int64_t tv_nsec = expiry.tv_nsec + (millis * 1e6);
|
int64_t tv_nsec = expiry.tv_nsec + (millis * 1e6);
|
||||||
if (tv_nsec > 1e9) {
|
if (tv_nsec > 1e9) {
|
||||||
int64_t sec_diff = tv_nsec / (int)1e6;
|
int64_t sec_diff = tv_nsec / static_cast<int> (1e6);
|
||||||
expiry.tv_nsec = tv_nsec - (int)(1e6 * sec_diff);
|
expiry.tv_nsec = tv_nsec - static_cast<int> (1e6 * sec_diff);
|
||||||
expiry.tv_sec += sec_diff;
|
expiry.tv_sec += sec_diff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -314,7 +314,7 @@ Serial::SerialImpl::reconfigurePort ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set custom divisor
|
// set custom divisor
|
||||||
ser.custom_divisor = ser.baud_base / (int) baudrate_;
|
ser.custom_divisor = ser.baud_base / static_cast<int> (baudrate_);
|
||||||
// update flags
|
// update flags
|
||||||
ser.flags &= ~ASYNC_SPD_MASK;
|
ser.flags &= ~ASYNC_SPD_MASK;
|
||||||
ser.flags |= ASYNC_SPD_CUST;
|
ser.flags |= ASYNC_SPD_CUST;
|
||||||
@ -476,7 +476,7 @@ Serial::SerialImpl::read (uint8_t *buf, size_t size)
|
|||||||
|
|
||||||
// Timeout for the next select is whichever is less of the remaining
|
// Timeout for the next select is whichever is less of the remaining
|
||||||
// total read timeout and the inter-byte timeout.
|
// total read timeout and the inter-byte timeout.
|
||||||
timespec timeout(timespec_from_ms(std::min((uint32_t)timeout_remaining_ms,
|
timespec timeout(timespec_from_ms(std::min(static_cast<uint32_t> (timeout_remaining_ms),
|
||||||
timeout_.inter_byte_timeout)));
|
timeout_.inter_byte_timeout)));
|
||||||
|
|
||||||
FD_ZERO (&readfds);
|
FD_ZERO (&readfds);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user