Skip to content

Commit c477b71

Browse files
committed
Use uint8_t in RTC BCD conversion helpers
Change `BCD2DEC` and `DEC2BCD` in the GD32F4/H7 RTC code to return `uint8_t` and use explicit unsigned casts/constants in the arithmetic. This tightens type usage for byte-sized BCD values and avoids implicit signed/int conversions.
1 parent 6dbdf07 commit c477b71

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)