Fix couple compiler warnings (#737)

* linux/bip6: Use function over PRINTF macro

Our repo should be C89 compatibale. C89 does not support variac macros.
For this reason use variac functions. This also enables to print
different streams than just stderr.

Also now if something is changed in debug_fprintf it also affect here
which is good.

* Use __inline__ over inline in library

Use __inline__ over inline as that is C89/C90 combatible. With MSVC we
need to use __inline so just define __inline__ to it if not already.

* h_get_alarm_sum: Fix -Wself-assign compiler warning

We get Wself-assign if PRINT_ENABLED is 0

```
src/bacnet/basic/service/h_get_alarm_sum.c:129:16:
  warning: explicitly assigning value of variable of type 'int' to itself
  [-Wself-assign]
[build]   129 |     bytes_sent = bytes_sent;
[build]       |     ~~~~~~~~~~ ^ ~~~~~~~~~~
```

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
This commit is contained in:
Kari Argillander
2024-08-21 17:44:31 +03:00
committed by GitHub
parent 5c20e6d505
commit d92edd359f
5 changed files with 41 additions and 21 deletions
+32 -15
View File
@@ -15,21 +15,38 @@
#include "bacnet/datalink/bip6.h" #include "bacnet/datalink/bip6.h"
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/bbmd6/h_bbmd6.h" #include "bacnet/basic/bbmd6/h_bbmd6.h"
#if DEBUG_ENABLED
#include "bacnet/basic/sys/debug.h"
#endif
#include "bacport.h" #include "bacport.h"
/* enable debugging */ /* enable debugging */
static bool BIP6_Debug = false; static bool BIP6_Debug = false;
#if PRINT_ENABLED
#include <stdarg.h> /**
#include <stdio.h> * @brief Conditionally use the debug_printf function
#define PRINTF(...) \ *
if (BIP6_Debug) { \ * @param stream - file stream to print to
fprintf(stderr,__VA_ARGS__); \ * @param format - printf format string
fflush(stderr); \ * @param ... - variable arguments
* @note This function is only works if
* PRINT_ENABLED and BIP6_Debug is non-zero
*/
static void debug_fprintf_bip6(FILE *stream, const char *format, ...)
{
#if DEBUG_ENABLED
va_list ap;
if (BIP6_Debug) {
va_start(ap, format);
debug_fprintf(stream, format, ap);
va_end(ap);
} }
#else #else
#define PRINTF(...) (void)stream;
(void)format;
#endif #endif
}
/** /**
* @brief Print the IPv6 address with debug info * @brief Print the IPv6 address with debug info
@@ -38,7 +55,7 @@ static bool BIP6_Debug = false;
*/ */
static void debug_print_ipv6(const char *str, const struct in6_addr *addr) static void debug_print_ipv6(const char *str, const struct in6_addr *addr)
{ {
PRINTF("BIP6: %s " debug_fprintf_bip6(stdout, "BIP6: %s "
"%02x%02x:%02x%02x:%02x%02x:%02x%02x:" "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
"%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", "%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
str, (int)addr->s6_addr[0], (int)addr->s6_addr[1], str, (int)addr->s6_addr[0], (int)addr->s6_addr[1],
@@ -84,12 +101,12 @@ void bip6_set_interface(char *ifname)
exit(1); exit(1);
} }
ifa_tmp = ifa; ifa_tmp = ifa;
if (BIP6_Debug) { debug_fprintf_bip6(stdout, "BIP6: seeking interface: %s\n", ifname);
PRINTF("BIP6: seeking interface: %s\n", ifname);
}
while (ifa_tmp) { while (ifa_tmp) {
if ((ifa_tmp->ifa_addr) && (ifa_tmp->ifa_addr->sa_family == AF_INET6)) { if ((ifa_tmp->ifa_addr) && (ifa_tmp->ifa_addr->sa_family == AF_INET6)) {
PRINTF("BIP6: found interface: %s\n", ifa_tmp->ifa_name); debug_fprintf_bip6(
stdout, "BIP6: found interface: %s\n",ifa_tmp->ifa_name);
} }
if ((ifa_tmp->ifa_addr) && (ifa_tmp->ifa_addr->sa_family == AF_INET6) && if ((ifa_tmp->ifa_addr) && (ifa_tmp->ifa_addr->sa_family == AF_INET6) &&
(strcasecmp(ifa_tmp->ifa_name, ifname) == 0)) { (strcasecmp(ifa_tmp->ifa_name, ifname) == 0)) {
@@ -110,7 +127,7 @@ void bip6_set_interface(char *ifname)
ifa_tmp = ifa_tmp->ifa_next; ifa_tmp = ifa_tmp->ifa_next;
} }
if (!found) { if (!found) {
PRINTF("BIP6: unable to set interface: %s\n", ifname); debug_fprintf_bip6(stderr, "BIP6: unable to set interface: %s\n", ifname);
exit(1); exit(1);
} }
} }
@@ -398,7 +415,7 @@ bool bip6_init(char *ifname)
if (BIP6_Addr.port == 0) { if (BIP6_Addr.port == 0) {
bip6_set_port(0xBAC0U); bip6_set_port(0xBAC0U);
} }
PRINTF("BIP6: IPv6 UDP port: 0x%04X\n", BIP6_Addr.port); debug_fprintf_bip6(stdout, "BIP6: IPv6 UDP port: 0x%04X\n", BIP6_Addr.port);
if (BIP6_Broadcast_Addr.address[0] == 0) { if (BIP6_Broadcast_Addr.address[0] == 0) {
bvlc6_address_set(&BIP6_Broadcast_Addr, BIP6_MULTICAST_SITE_LOCAL, 0, 0, bvlc6_address_set(&BIP6_Broadcast_Addr, BIP6_MULTICAST_SITE_LOCAL, 0, 0,
0, 0, 0, 0, BIP6_MULTICAST_GROUP_ID); 0, 0, 0, 0, BIP6_MULTICAST_GROUP_ID);
+1 -1
View File
@@ -126,7 +126,7 @@ GET_ALARM_SUMMARY_ABORT:
/*fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); */ /*fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); */
} }
#else #else
bytes_sent = bytes_sent; (void)bytes_sent;
#endif #endif
return; return;
+3
View File
@@ -52,6 +52,9 @@
#ifndef strncasecmp #ifndef strncasecmp
#define strncasecmp _strnicmp #define strncasecmp _strnicmp
#endif #endif
#ifndef __inline__
#define __inline__ __inline
#endif
#if (_MSC_VER < 1900) #if (_MSC_VER < 1900)
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
+1 -1
View File
@@ -15,7 +15,7 @@
static struct uci_ptr ptr; static struct uci_ptr ptr;
static inline int ucix_get_ptr(struct uci_context *ctx, static __inline__ int ucix_get_ptr(struct uci_context *ctx,
const char *p, const char *p,
const char *s, const char *s,
const char *o, const char *o,
+4 -4
View File
@@ -44,7 +44,7 @@
#if defined(PRINT_ENABLED_RECEIVE) #if defined(PRINT_ENABLED_RECEIVE)
#define printf_receive debug_printf #define printf_receive debug_printf
#else #else
static inline void printf_receive(const char *format, ...) static __inline__ void printf_receive(const char *format, ...)
{ {
(void)format; (void)format;
} }
@@ -53,7 +53,7 @@ static inline void printf_receive(const char *format, ...)
#if defined(PRINT_ENABLED_RECEIVE_DATA) #if defined(PRINT_ENABLED_RECEIVE_DATA)
#define printf_receive_data debug_printf #define printf_receive_data debug_printf
#else #else
static inline void printf_receive_data(const char *format, ...) static __inline__ void printf_receive_data(const char *format, ...)
{ {
(void)format; (void)format;
} }
@@ -62,7 +62,7 @@ static inline void printf_receive_data(const char *format, ...)
#if defined(PRINT_ENABLED_RECEIVE_ERRORS) #if defined(PRINT_ENABLED_RECEIVE_ERRORS)
#define printf_receive_error debug_printf #define printf_receive_error debug_printf
#else #else
static inline void printf_receive_error(const char *format, ...) static __inline__ void printf_receive_error(const char *format, ...)
{ {
(void)format; (void)format;
} }
@@ -71,7 +71,7 @@ static inline void printf_receive_error(const char *format, ...)
#if defined(PRINT_ENABLED_MASTER) #if defined(PRINT_ENABLED_MASTER)
#define printf_master debug_printf #define printf_master debug_printf
#else #else
static inline void printf_master(const char *format, ...) static __inline__ void printf_master(const char *format, ...)
{ {
(void)format; (void)format;
} }