Bugfix/bacaddr dnet only init (#570)
* Fixed bacnet_address_init() when setting only the dnet value. * Fixed MSVC snprintf from C99
This commit is contained in:
@@ -156,7 +156,7 @@ bool bacnet_address_init(BACNET_ADDRESS *dest,
|
|||||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||||
dest->mac[i] = 0;
|
dest->mac[i] = 0;
|
||||||
}
|
}
|
||||||
dest->mac_len = mac->len;
|
dest->mac_len = 0;
|
||||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||||
dest->adr[i] = 0;
|
dest->adr[i] = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* @file
|
* @file
|
||||||
* @author Steve Karg
|
* @author Steve Karg
|
||||||
* @date 2022
|
* @date 2022
|
||||||
* @brief Platform libc and compiler abstraction layer
|
* @brief Platform libc and compiler abstraction layer
|
||||||
*
|
*
|
||||||
* @section DESCRIPTION
|
* @section DESCRIPTION
|
||||||
*
|
*
|
||||||
@@ -40,10 +40,44 @@
|
|||||||
# define BACNET_STACK_DEPRECATED(message)
|
# define BACNET_STACK_DEPRECATED(message)
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#if defined(WIN32) || defined(WIN64)
|
#if defined(_MSC_VER)
|
||||||
|
#ifndef strcasecmp
|
||||||
#define strcasecmp _stricmp
|
#define strcasecmp _stricmp
|
||||||
|
#endif
|
||||||
|
#ifndef strncasecmp
|
||||||
#define strncasecmp _strnicmp
|
#define strncasecmp _strnicmp
|
||||||
#define snprintf _snprintf
|
#endif
|
||||||
|
#if (_MSC_VER < 1900)
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#define snprintf c99_snprintf
|
||||||
|
#define vsnprintf c99_vsnprintf
|
||||||
|
|
||||||
|
__inline int c99_vsnprintf(char *outBuf, size_t size, const char *format,
|
||||||
|
va_list ap)
|
||||||
|
{
|
||||||
|
int count = -1;
|
||||||
|
|
||||||
|
if (size != 0)
|
||||||
|
count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
|
||||||
|
if (count == -1)
|
||||||
|
count = _vscprintf(format, ap);
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
__inline int c99_snprintf(char *outBuf, size_t size, const char *format, ...)
|
||||||
|
{
|
||||||
|
int count;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
count = c99_vsnprintf(outBuf, size, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#elif defined(__ZEPHYR__)
|
#elif defined(__ZEPHYR__)
|
||||||
# include <strings.h>
|
# include <strings.h>
|
||||||
# endif
|
# endif
|
||||||
@@ -62,7 +96,7 @@
|
|||||||
#define BACNET_STACK_FALLTHROUGH() /* fall through */
|
#define BACNET_STACK_FALLTHROUGH() /* fall through */
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
#define BACNET_STACK_FALLTHROUGH() __attribute__ ((fallthrough))
|
#define BACNET_STACK_FALLTHROUGH() __attribute__ ((fallthrough))
|
||||||
#else
|
#else
|
||||||
#define BACNET_STACK_FALLTHROUGH() /* fall through */
|
#define BACNET_STACK_FALLTHROUGH() /* fall through */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -99,6 +99,14 @@ static void test_BACNET_ADDRESS(void)
|
|||||||
dest.mac_len = 1;
|
dest.mac_len = 1;
|
||||||
status = bacnet_address_same(&dest, &src);
|
status = bacnet_address_same(&dest, &src);
|
||||||
zassert_false(status, NULL);
|
zassert_false(status, NULL);
|
||||||
|
/* only setting a DNET address */
|
||||||
|
dnet = 1234;
|
||||||
|
status = bacnet_address_init(&dest, NULL, dnet, NULL);
|
||||||
|
zassert_true(status, NULL);
|
||||||
|
status = bacnet_address_init(&src, NULL, dnet, NULL);
|
||||||
|
zassert_true(status, NULL);
|
||||||
|
status = bacnet_address_same(&dest, &src);
|
||||||
|
zassert_true(status, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_ZTEST_NEW_API)
|
#if defined(CONFIG_ZTEST_NEW_API)
|
||||||
|
|||||||
Reference in New Issue
Block a user