Skip to content

Commit ab31329

Browse files
committed
Clean up casts and DMX config guards
Improve type-safety and warning hygiene in low-level helpers: `debug::PrintBits` now uses explicit unsigned casts with matching format specifiers, `inet_aton` is modernized (`nullptr`, scoped union alias, clearer declarations/casts), and `inet_ntoa` uses `auto*` for the byte pointer. In `displayudf.h`, DMX-related feature macros are reordered so `DMX_MAX_PORTS` is undefined before DMX node output headers are included, ensuring consistent configuration for relevant output modes. Copyright year ranges were also updated.
1 parent 3086f1a commit ab31329

5 files changed

Lines changed: 25 additions & 18 deletions

File tree

common/include/firmware/debug/debug_printbits.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@
2626
#ifndef COMMON_DEBUG_DEBUG_PRINTBITS_H_
2727
#define COMMON_DEBUG_DEBUG_PRINTBITS_H_
2828

29-
#include <cstdio>
3029
#include <cstdint>
3130

3231
namespace debug {
3332
#ifdef NDEBUG
3433
inline void PrintBits([[maybe_unused]] uint32_t u) {}
3534
#else
35+
#include <cstdio>
3636
inline void PrintBits(uint32_t u) {
37-
printf("%.8x ", u);
37+
printf("%.8x ", static_cast<unsigned>(u));
3838
uint32_t b = 1U << 31;
3939

4040
for (uint32_t i = 0; i < 32; i++) {
4141
if ((b & u) == b) {
4242
uint32_t bit_number = 31 - i;
43-
printf("%-2d ", bit_number);
43+
printf("%-2u ", static_cast<unsigned>(bit_number));
4444
}
4545
b = b >> 1;
4646
}
@@ -50,4 +50,4 @@ inline void PrintBits(uint32_t u) {
5050
#endif
5151
} // namespace debug
5252

53-
#endif /* COMMON_DEBUG_DEBUG_PRINTBITS_H_ */
53+
#endif // COMMON_DEBUG_DEBUG_PRINTBITS_H_

lib-clib/src/inet_aton.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file inet_aton.cpp
33
*
44
*/
5-
/* Copyright (C) 2016-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2016-2026 by Arjan van Vught mailto:info@gd32-dmx.org
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -27,14 +27,18 @@
2727
#include <cctype>
2828
#include <netinet/in.h>
2929

30-
typedef union pcast32 {
30+
namespace {
31+
using _pcast32 = union pcast32 {
3132
uint32_t u32;
3233
uint8_t u8[4];
33-
} _pcast32;
34+
};
35+
} // namespace
3436

3537
extern "C" int inet_aton(const char* cp, struct in_addr* ip_address) {
3638
const char* b = cp;
37-
int i, j, k;
39+
int i;
40+
int j;
41+
int k;
3842
_pcast32 cast32;
3943

4044
for (i = 0; i < 3; i++) {
@@ -46,12 +50,12 @@ extern "C" int inet_aton(const char* cp, struct in_addr* ip_address) {
4650
return 0;
4751
}
4852

49-
if (0 == isdigit((int)*b)) {
53+
if (0 == isdigit(static_cast<int>(*b))) {
5054
return 0;
5155
}
5256

5357
j++;
54-
k = k * 10 + (int)*b - (int)'0';
58+
k = (k * 10) + static_cast<int>(*b) - '0';
5559
b++;
5660
}
5761

@@ -72,13 +76,13 @@ extern "C" int inet_aton(const char* cp, struct in_addr* ip_address) {
7276
}
7377

7478
j++;
75-
k = k * 10 + (int)*b - (int)'0';
79+
k = (k * 10) + static_cast<int>(*b) - '0';
7680
b++;
7781
}
7882

7983
cast32.u8[i] = (uint8_t)k;
8084

81-
if (ip_address != 0) {
85+
if (ip_address != nullptr) {
8286
ip_address->s_addr = cast32.u32;
8387
}
8488

lib-clib/src/inet_ntoa.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
static char buffer[18];
3030

3131
extern "C" char* inet_ntoa(struct in_addr in) {
32-
unsigned char* bytes = (unsigned char*)&in;
32+
auto* bytes = (unsigned char*)&in;
3333
snprintf(buffer, sizeof(buffer), "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3]);
3434
return buffer;
3535
}

lib-displayudf/include/displayudf.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file displayudf.h
33
*
44
*/
5-
/* Copyright (C) 2019-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2019-2026 by Arjan van Vught mailto:info@gd32-dmx.org
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -51,13 +51,16 @@
5151
#if defined(RDM_RESPONDER)
5252
#include "rdmdeviceresponder.h"
5353
#endif
54+
#if defined(RDM_RESPONDER) || defined(OUTPUT_DMX_MONITOR) || defined(OUTPUT_DMX_PCA9685) || defined(OUTPUT_DMX_PIXEL) || defined(OUTPUT_DMX_TLC59711)
55+
#define HAVE_DMX_START_ADDRESS
56+
#endif
57+
#if defined(RDM_RESPONDER) || defined(OUTPUT_DMX_MONITOR) || defined(OUTPUT_DMX_PCA9685) || defined(OUTPUT_DMX_TLC59711)
58+
#undef DMX_MAX_PORTS
59+
#endif
5460
#include "dmxnode_outputtype.h"
5561
#if defined(DMXNODE_OUTPUT_DMX)
5662
#include "dmx.h"
5763
#endif
58-
#if defined(RDM_RESPONDER) || defined(OUTPUT_DMX_MONITOR) || defined(OUTPUT_DMX_PCA9685) || defined(OUTPUT_DMX_PIXEL) || defined(OUTPUT_DMX_TLC59711)
59-
#define HAVE_DMX_START_ADDRESS
60-
#endif
6164

6265
namespace displayudf {
6366
inline constexpr uint32_t kLabelMaxRows = 6;

lib-dmxnode/src/json/json_config_dmxnode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file json_config_dmxnode.cpp
33
*/
4-
/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org
4+
/* Copyright (C) 2025-2026 by Arjan van Vught mailto:info@gd32-dmx.org
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)