Skip to content

Commit 1e73fcd

Browse files
committed
Use uint8_t in RTC BCD conversion helpers
Update `BCD2DEC` and `DEC2BCD` in `hwclockrtc.cpp` to return `uint8_t` and use explicit `static_cast<uint8_t>`/unsigned literals in the math. This tightens type safety for RTC BCD conversions and avoids implicit signed-integer behavior.
1 parent fb94154 commit 1e73fcd

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

lib-hwclock/src/gd32/internal/hwclockrtc.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747
#include "gd32.h"
4848

4949
#if defined(GD32F4XX) || defined(GD32H7XX)
50-
static int BCD2DEC(int val) {
51-
return (((val) & 0x0f) + (val >> 4) * 10);
50+
static uint8_t BCD2DEC(int val) {
51+
return static_cast<uint8_t>(((val) & 0x0f) + static_cast<uint8_t>(val >> 4) * 10U);
5252
}
5353

54-
static int DEC2BCD(int val) {
55-
return ((((val) / 10) << 4) + val % 10);
54+
static uint8_t DEC2BCD(int val) {
55+
return static_cast<uint8_t>(((static_cast<uint8_t>(val) / 10U) << 4) + (static_cast<uint8_t>(val) % 10U));
5656
}
5757
#define RTC_CLOCK_SOURCE_LXTAL
5858
static rtc_parameter_struct rtc_initpara;

0 commit comments

Comments
 (0)