Skip to content

Commit f087f1a

Browse files
committed
Normalize console error messages and fixes
Append trailing newlines to diagnostic console::Error calls across multiple modules (malloc, software timers, DHCP, IGMP, TCP, UDP) for consistent output formatting. Add console::Write declaration and replace console::Puts(": ") with console::Write(": ", 2) in perror to use a write-with-length API. Add missing <cstdint> include in UART console implementation and bump copyright year in perror.cpp.
1 parent 6bf1e7d commit f087f1a

File tree

8 files changed

+18
-16
lines changed

8 files changed

+18
-16
lines changed

lib-clib/src/malloc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ extern "C"
150150

151151
if (next > block_limit)
152152
{
153-
console::Error("malloc: out of memory");
153+
console::Error("malloc: out of memory\n");
154154
#ifdef DEBUG_HEAP
155155
debug_heap();
156156
#endif

lib-clib/src/perror.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file perror.cpp
33
*
44
*/
5-
/* Copyright (C) 2020-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2020-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
@@ -31,6 +31,7 @@ namespace console
3131
void Error(const char*);
3232
int Putc(int);
3333
int Puts(const char*);
34+
void Write(const char*, unsigned int);
3435
} // namespace console
3536

3637
/*
@@ -107,7 +108,7 @@ extern "C"
107108
if (s && *s)
108109
{
109110
console::Error(s);
110-
console::Puts(": ");
111+
console::Write(": ", 2);
111112
}
112113

113114
console::Error(ptr);

lib-hal/console/uart0/console.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* THE SOFTWARE.
2424
*/
2525

26+
#include <cstdint>
2627
#include <cstring>
2728

2829
#include "console.h"

lib-hal/superloop/softwaretimers.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ TimerHandle_t SoftwareTimerAdd(uint32_t interval_millis, const TimerCallbackFunc
7777
if (s_timers_count >= hal::kSoftwareTimersMax)
7878
{
7979
#ifndef NDEBUG
80-
console::Error("SoftwareTimerAdd: Max timer limit reached");
80+
console::Error("SoftwareTimerAdd: Max timer limit reached\n");
8181
#endif
8282
return -1;
8383
}
@@ -134,7 +134,7 @@ bool SoftwareTimerDelete(TimerHandle_t& id)
134134
}
135135

136136
#ifndef NDEBUG
137-
console::Error("SoftwareTimerDelete: Timer not found");
137+
console::Error("SoftwareTimerDelete: Timer not found\n");
138138
#endif
139139

140140
DEBUG_EXIT();
@@ -163,7 +163,7 @@ bool SoftwareTimerChange(TimerHandle_t id, uint32_t interval_millis)
163163
}
164164

165165
#ifndef NDEBUG
166-
console::Error("SoftwareTimerChange: Timer not found");
166+
console::Error("SoftwareTimerChange: Timer not found\n");
167167
#endif
168168

169169
return false;

lib-network/src/core/ipv4/dhcp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void Inform()
250250
#ifndef NDEBUG
251251
if (kHandle < 0)
252252
{
253-
console::Error("DHCP Inform");
253+
console::Error("DHCP Inform\n");
254254
return;
255255
}
256256
#endif
@@ -766,7 +766,7 @@ bool Start()
766766
#ifndef NDEBUG
767767
if (dhcp->handle < 0)
768768
{
769-
console::Error("DHCP Start");
769+
console::Error("DHCP Start\n");
770770
DEBUG_EXIT();
771771
return false;
772772
}

lib-network/src/core/ipv4/igmp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ void static Join(uint32_t group_address)
378378
}
379379

380380
#ifndef NDEBUG
381-
console::Error("igmp::Join");
381+
console::Error("igmp::Join\n");
382382
#endif
383383
DEBUG_ENTRY();
384384
}

lib-network/src/core/tcp.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ int32_t Connect(uint32_t remote_ip, uint16_t remote_port, CallbackConnect cb_con
16641664
const auto& netif = netif::global::netif_default;
16651665
if (__builtin_expect((netif.ip.addr == 0), 0))
16661666
{
1667-
console::Error("Connect: No ip!");
1667+
console::Error("Connect: No ip!\n");
16681668
return -1;
16691669
}
16701670

@@ -1673,7 +1673,7 @@ int32_t Connect(uint32_t remote_ip, uint16_t remote_port, CallbackConnect cb_con
16731673
auto* tcb = AllocTcb(remote_port, &out_index);
16741674
if (tcb == nullptr)
16751675
{
1676-
console::Error("Connect: No TCB!");
1676+
console::Error("Connect: No TCB!\n");
16771677
return -2;
16781678
}
16791679

@@ -1714,15 +1714,15 @@ int32_t Close(ConnHandle conn_handle) // graceful FIN
17141714
{
17151715
if (conn_handle >= TCP_MAX_TCBS_ALLOWED)
17161716
{
1717-
console::Error("Close: Connection handle!");
1717+
console::Error("Close: Connection handle!\n");
17181718
return -1;
17191719
}
17201720

17211721
auto* c = &s_tcbs[conn_handle];
17221722

17231723
if (!c->in_use || c->state == kStateClosed)
17241724
{
1725-
console::Error("Close: TCB!");
1725+
console::Error("Close: TCB!\n");
17261726
return -1;
17271727
}
17281728

@@ -1743,7 +1743,7 @@ int32_t Close(ConnHandle conn_handle) // graceful FIN
17431743
// We only support graceful close from states where FIN makes sense here.
17441744
if (c->state != kStateEstablished && c->state != kStateCloseWait)
17451745
{
1746-
console::Error("Close: Not graceful!");
1746+
console::Error("Close: Not graceful!\n");
17471747
return -1;
17481748
}
17491749

lib-network/src/core/udp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ int32_t Begin(uint16_t localport, UdpCallbackFunctionPtr callback)
249249
}
250250

251251
#ifndef NDEBUG
252-
console::Error("network::udp::Begin");
252+
console::Error("network::udp::Begin\n");
253253
#endif
254254
return -1;
255255
}
@@ -274,7 +274,7 @@ int32_t End(uint16_t localport)
274274
}
275275

276276
#ifndef NDEBUG
277-
console::Error("network::udp::End");
277+
console::Error("network::udp::End\n");
278278
#endif
279279
return -1;
280280
}

0 commit comments

Comments
 (0)