From c256b78abc187caaab64cfbf476a2b567fbf12ef Mon Sep 17 00:00:00 2001 From: Julius Pfrommer Date: Wed, 8 Feb 2017 20:17:25 +0100 Subject: [PATCH] make UA_readNumber an internal function --- include/ua_connection.h | 6 ------ src/ua_connection.c | 6 +++--- src/ua_util.h | 10 +++++++++- tests/check_utils.c | 1 + 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/include/ua_connection.h b/include/ua_connection.h index e713535f3..4b1c7e58d 100644 --- a/include/ua_connection.h +++ b/include/ua_connection.h @@ -125,12 +125,6 @@ UA_StatusCode UA_EXPORT UA_EndpointUrl_split(const char *endpointUrl, char *hostname, UA_UInt16 * port, const char ** path); -/* Convert given byte string to a positive number. Returns the number of valid - * digits. Stops if a non-digit char is found and returns the number of digits - * up to that point. */ -size_t UA_EXPORT -UA_readNumber(UA_Byte *buf, size_t buflen, UA_UInt32 *number); - #ifdef __cplusplus } // extern "C" #endif diff --git a/src/ua_connection.c b/src/ua_connection.c index 1a56c4e02..160d0826d 100644 --- a/src/ua_connection.c +++ b/src/ua_connection.c @@ -313,14 +313,14 @@ UA_EndpointUrl_split(const char *endpointUrl, char *hostname, } size_t UA_readNumber(UA_Byte *buf, size_t buflen, UA_UInt32 *number) { - if (!buf) - return 0; + UA_assert(buf); + UA_assert(number); UA_UInt32 n = 0; size_t progress = 0; /* read numbers until the end or a non-number character appears */ while(progress < buflen) { UA_Byte c = buf[progress]; - if('0' > c || '9' < c) + if(c < '0' || c > '9') break; n = (n*10) + (UA_UInt32)(c-'0'); ++progress; diff --git a/src/ua_util.h b/src/ua_util.h index 012c9dbfe..512f74a2f 100644 --- a/src/ua_util.h +++ b/src/ua_util.h @@ -5,7 +5,7 @@ #ifndef UA_UTIL_H_ #define UA_UTIL_H_ -#include "ua_config.h" +#include "ua_types.h" #ifdef __cplusplus extern "C" { @@ -106,6 +106,14 @@ UA_atomic_add(volatile uint32_t *addr, uint32_t increase) { #endif } +/* Utility Functions + * ----------------- */ + +/* Convert given byte string to a positive number. Returns the number of valid + * digits. Stops if a non-digit char is found and returns the number of digits + * up to that point. */ +size_t UA_readNumber(UA_Byte *buf, size_t buflen, UA_UInt32 *number); + #ifdef __cplusplus } // extern "C" #endif diff --git a/tests/check_utils.c b/tests/check_utils.c index 1121caa5f..6eee3dc29 100644 --- a/tests/check_utils.c +++ b/tests/check_utils.c @@ -6,6 +6,7 @@ #include "ua_types.h" #include "ua_client.h" +#include "ua_util.h" #include "check.h" START_TEST(EndpointUrl_split) {