...
 
Commits (4)
......@@ -67,6 +67,9 @@ if(expat_FOUND)
set(expat_LIB expat::libexpat)
# Windows definition of cmake-expat lacks the headers
target_include_directories(${expat_LIB} INTERFACE "${expat_DIR}\\..\\..\\..\\include")
if (USE_STATIC_EXPAT_LIB)
target_compile_definitions(${expat_LIB} INTERFACE "XML_STATIC")
endif()
else()
set(expat_LIB expat::expat)
endif()
......
......@@ -61,7 +61,7 @@ test_script:
cd %EXPAT_DIR%
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=%EXPAT_INSTALL_DIR% .. -G "Visual Studio 15 2017 Win64"
cmake -DEXPAT_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=%EXPAT_INSTALL_DIR% .. -G "Visual Studio 15 2017 Win64"
cmake --build . --target install --config %CONFIG%
# configure, build and test S2OPC project
......@@ -73,7 +73,7 @@ test_script:
copy %MBEDTLS_DIR%\build\library\%CONFIG%\mbedtls.lib lib
copy %MBEDTLS_DIR%\build\library\%CONFIG%\mbedx509.lib lib
copy %MBEDTLS_DIR%\build\library\%CONFIG%\mbedcrypto.lib lib
copy %EXPAT_INSTALL_DIR%\lib\libexpat.lib lib
copy %EXPAT_INSTALL_DIR%\lib\libexpatMD.lib lib\libexpat.lib
cmake -DS2OPC_CLIENTSERVER_ONLY=%S2OPC_CLIENTSERVER_ONLY% -DMBEDTLS_INCLUDE_DIR=%MBEDTLS_BUILD_DIR%/../include -DMBEDTLS_LIBRARY=%MBEDTLS_BUILD_DIR%/library/%CONFIG%/mbedtls.lib -DMBEDX509_LIBRARY=%MBEDTLS_BUILD_DIR%/library/%CONFIG%/mbedx509.lib -DMBEDCRYPTO_LIBRARY=%MBEDTLS_BUILD_DIR%/library/%CONFIG%/mbedcrypto.lib -DCMAKE_PREFIX_PATH=%LIBS_DIRS% .. -G "Visual Studio 15 2017 Win64"
cmake --build . --config %CONFIG%
- cd %ROOT_DIR%\build\tests\ClientServer
......@@ -87,6 +87,6 @@ artifacts:
type: zip
on_failure:
- ps: $root = Resolve-Path .\Testing\; [IO.Directory]::GetFiles($root.Path, '*.*', 'AllDirectories') | % { Push-AppveyorArtifact $_ -FileName $_.Substring($root.Path.Length + 1) -DeploymentName to-publish }
- ps: $root = Resolve-Path $Env:APPVEYOR_BUILD_FOLDER\build; [IO.Directory]::GetFiles($root.Path, '*.*', 'AllDirectories') | % { Push-AppveyorArtifact $_ -FileName $_.Substring($root.Path.Length + 1) -DeploymentName to-publish }
#on_finish:
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
......@@ -253,7 +253,7 @@ bool SOPC_strtoint(const char* data, size_t len, uint8_t width, void* dest)
{
char buf[21];
if (len > (sizeof(buf) / sizeof(char) - 1))
if (NULL == dest || len == 0 || len > (sizeof(buf) / sizeof(char) - 1))
{
return false;
}
......@@ -261,46 +261,48 @@ bool SOPC_strtoint(const char* data, size_t len, uint8_t width, void* dest)
memcpy(buf, data, len);
buf[len] = '\0';
errno = 0;
char* endptr;
int64_t val = strtol(buf, &endptr, 10);
long long int val = strtoll(buf, &endptr, 10);
if (endptr != (buf + len))
{
return false;
}
bool res = true;
if (width == 8 && val >= INT8_MIN && val <= INT8_MAX)
{
*((int8_t*) dest) = (int8_t) val;
return true;
}
else if (width == 16 && val >= INT16_MIN && val <= INT16_MAX)
{
*((int16_t*) dest) = (int16_t) val;
return true;
}
else if (width == 32 && val >= INT32_MIN && val <= INT32_MAX)
{
*((int32_t*) dest) = (int32_t) val;
return true;
}
else if (width == 64)
else if (width == 64 && val >= INT64_MIN && val <= INT64_MAX &&
!((LLONG_MAX == val || LLONG_MIN == val) && ERANGE == errno))
{
*((int64_t*) dest) = (int64_t) val;
return true;
}
else
{
// Invalid width and/or out of bounds value
return false;
res = false;
}
return res;
}
bool SOPC_strtouint(const char* data, size_t len, uint8_t width, void* dest)
{
char buf[21];
if (len > (sizeof(buf) / sizeof(char) - 1))
if (NULL == dest || len == 0 || len > (sizeof(buf) / sizeof(char) - 1))
{
return false;
}
......@@ -309,45 +311,45 @@ bool SOPC_strtouint(const char* data, size_t len, uint8_t width, void* dest)
buf[len] = '\0';
char* endptr;
uint64_t val = strtoul(buf, &endptr, 10);
errno = 0;
unsigned long long int val = strtoull(buf, &endptr, 10);
if (endptr != (buf + len))
{
return false;
}
bool res = true;
if (width == 8 && val <= UINT8_MAX)
{
*((uint8_t*) dest) = (uint8_t) val;
return true;
}
else if (width == 16 && val <= UINT16_MAX)
{
*((uint16_t*) dest) = (uint16_t) val;
return true;
}
else if (width == 32 && val <= UINT32_MAX)
{
*((uint32_t*) dest) = (uint32_t) val;
return true;
}
else if (width == 64)
else if (width == 64 && val <= UINT64_MAX && !(ULLONG_MAX == val && ERANGE == errno))
{
*((uint64_t*) dest) = (uint64_t) val;
return true;
}
else
{
// Invalid width and/or out of bounds value
return false;
res = false;
}
return res;
}
bool SOPC_strtodouble(const char* data, size_t len, uint8_t width, void* dest)
{
char buf[340];
if (len > (sizeof(buf) / sizeof(char) - 1))
if (NULL == dest || len <= 0 || len > (sizeof(buf) / sizeof(char) - 1))
{
return false;
}
......@@ -356,6 +358,7 @@ bool SOPC_strtodouble(const char* data, size_t len, uint8_t width, void* dest)
buf[len] = '\0';
char* endptr;
errno = 0;
double val = strtod(buf, &endptr);
if (endptr != (buf + len))
......@@ -363,21 +366,22 @@ bool SOPC_strtodouble(const char* data, size_t len, uint8_t width, void* dest)
return false;
}
if (width == 32 && val >= -FLT_MAX && val <= FLT_MAX)
bool res = true;
if (width == 32 && val >= -FLT_MAX && val <= FLT_MAX && ERANGE != errno)
{
*((float*) dest) = (float) val;
return true;
}
else if (width == 64 && val >= -DBL_MAX && val <= DBL_MAX)
else if (width == 64 && val >= -DBL_MAX && val <= DBL_MAX && ERANGE != errno)
{
*((double*) dest) = val;
return true;
}
else
{
// Invalid width and/or out of bounds value
return false;
res = false;
}
return res;
}
char* SOPC_strdup(const char* s)
......
......@@ -106,7 +106,7 @@ SOPC_ReturnStatus SOPC_strtouint16_t(const char* sz, uint16_t* n, int base, char
SOPC_ReturnStatus SOPC_strtouint32_t(const char* sz, uint32_t* n, int base, char cEnd);
/**
* \brief Read a signed integer from the string with strtol.
* \brief Read a signed integer from the string with strtoll.
*
* \param data A pointer to the CString containing the number in base 10
* \param len The length of the CString to use for parsing, it shall be <= 20
......@@ -118,7 +118,7 @@ SOPC_ReturnStatus SOPC_strtouint32_t(const char* sz, uint32_t* n, int base, char
bool SOPC_strtoint(const char* data, size_t len, uint8_t width, void* dest);
/**
* \brief Read an unsigned integer from the string with strtoul.
* \brief Read an unsigned integer from the string with strtoull.
*
* \param data A pointer to the CString containing the number in base 10
* \param len The length of the CString to use for parsing, it shall be <= 20
......
......@@ -1403,6 +1403,255 @@ START_TEST(test_strtouint)
}
END_TEST
START_TEST(test_strtouint2)
{
uint8_t a = 0;
uint16_t b = 0;
uint32_t c = 0;
uint64_t d = 0;
/* 8 */
ck_assert(SOPC_strtouint("0", strlen("0"), 8, &a));
ck_assert(0 == a);
ck_assert(SOPC_strtouint("42", strlen("42"), 8, &a));
ck_assert(42 == a);
ck_assert(!SOPC_strtouint("42;3", strlen("42;3"), 8, &a));
ck_assert(SOPC_strtouint("42;3", 2, 8, &a));
ck_assert(42 == a);
ck_assert(!SOPC_strtouint("42zz-24", strlen("42zz-24"), 8, &a));
ck_assert(SOPC_strtouint("42zz-24", 2, 8, &a));
ck_assert(42 == a);
ck_assert(!SOPC_strtouint("", strlen(""), 8, &a));
ck_assert(!SOPC_strtouint(NULL, 0, 8, &a));
ck_assert(!SOPC_strtouint("42", strlen("42"), 8, NULL));
ck_assert(SOPC_strtouint("255", strlen("255"), 8, &a));
ck_assert(0xFF == a);
ck_assert(!SOPC_strtouint("256", strlen("256"), 8, &a));
/* 16 */
ck_assert(SOPC_strtouint("0", strlen("0"), 16, &b));
ck_assert(0 == b);
ck_assert(SOPC_strtouint("42", strlen("42"), 16, &b));
ck_assert(42 == b);
ck_assert(!SOPC_strtouint("", strlen(""), 16, &b));
ck_assert(!SOPC_strtouint(NULL, 0, 16, &b));
ck_assert(!SOPC_strtouint("42", strlen("42"), 16, NULL));
ck_assert(SOPC_strtouint("255", strlen("255"), 16, &b));
ck_assert(0xFF == b);
ck_assert(SOPC_strtouint("256", strlen("256"), 16, &b));
ck_assert(0x100 == b);
ck_assert(SOPC_strtouint("65535", strlen("65535"), 16, &b));
ck_assert(0xFFFF == b);
ck_assert(!SOPC_strtouint("65536", strlen("65536"), 16, &b));
/* 32 */
ck_assert(SOPC_strtouint("0", strlen("0"), 32, &c));
ck_assert(0 == c);
ck_assert(SOPC_strtouint("42", strlen("42"), 32, &c));
ck_assert(42 == c);
ck_assert(!SOPC_strtouint("", strlen(""), 32, &c));
ck_assert(!SOPC_strtouint(NULL, 0, 32, &c));
ck_assert(!SOPC_strtouint("42", strlen("42"), 32, NULL));
ck_assert(SOPC_strtouint("255", strlen("255"), 32, &c));
ck_assert(0xFF == c);
ck_assert(SOPC_strtouint("256", strlen("256"), 32, &c));
ck_assert(0x100 == c);
ck_assert(SOPC_strtouint("65535", strlen("65535"), 32, &c));
ck_assert(0xFFFF == c);
ck_assert(SOPC_strtouint("65536", strlen("65536"), 32, &c));
ck_assert(0x10000 == c);
ck_assert(SOPC_strtouint("4294967295", strlen("4294967295"), 32, &c));
ck_assert(0xFFFFFFFF == c);
ck_assert(!SOPC_strtouint("4294967296", strlen("4294967296"), 32, &c));
/* 64 */
ck_assert(SOPC_strtouint("0", strlen("0"), 64, &d));
ck_assert(0 == d);
ck_assert(SOPC_strtouint("42", strlen("42"), 64, &d));
ck_assert(42 == d);
ck_assert(!SOPC_strtouint("", strlen(""), 64, &d));
ck_assert(!SOPC_strtouint(NULL, 0, 64, &d));
ck_assert(!SOPC_strtouint("42", strlen("42"), 64, NULL));
ck_assert(SOPC_strtouint("255", strlen("255"), 64, &d));
ck_assert(0xFF == d);
ck_assert(SOPC_strtouint("256", strlen("256"), 64, &d));
ck_assert(0x100 == d);
ck_assert(SOPC_strtouint("65535", strlen("65535"), 64, &d));
ck_assert(0xFFFF == d);
ck_assert(SOPC_strtouint("65536", strlen("65536"), 64, &d));
ck_assert(0x10000 == d);
ck_assert(SOPC_strtouint("4294967295", strlen("4294967295"), 64, &d));
ck_assert(0xFFFFFFFF == d);
ck_assert(SOPC_strtouint("4294967296", strlen("4294967296"), 64, &d));
ck_assert(0x100000000 == d);
ck_assert(SOPC_strtouint("18446744073709551615", strlen("18446744073709551615"), 64, &d));
ck_assert(0xFFFFFFFFFFFFFFFF == d);
ck_assert(!SOPC_strtouint("18446744073709551616", strlen("18446744073709551616"), 64, &d));
}
END_TEST
START_TEST(test_strtoint)
{
int8_t a = 0;
int16_t b = 0;
int32_t c = 0;
int64_t d = 0;
/* 8 */
ck_assert(SOPC_strtoint("0", strlen("0"), 8, &a));
ck_assert(0 == a);
ck_assert(SOPC_strtoint("42", strlen("42"), 8, &a));
ck_assert(42 == a);
ck_assert(!SOPC_strtoint("", strlen(""), 8, &a));
ck_assert(!SOPC_strtoint(NULL, 0, 8, &a));
ck_assert(!SOPC_strtoint("42", strlen("42"), 8, NULL));
ck_assert(!SOPC_strtouint("42;3", strlen("42;3"), 8, &a));
ck_assert(SOPC_strtouint("42;3", 2, 8, &a));
ck_assert(42 == a);
ck_assert(!SOPC_strtouint("42zz-24", strlen("42zz-24"), 8, &a));
ck_assert(SOPC_strtouint("42zz-24", 2, 8, &a));
ck_assert(42 == a);
ck_assert(SOPC_strtoint("-128", strlen("-128"), 8, &a));
ck_assert(INT8_MIN == a);
ck_assert(!SOPC_strtoint("-129", strlen("-129"), 8, &a));
ck_assert(SOPC_strtoint("127", strlen("127"), 8, &a));
ck_assert(INT8_MAX == a);
ck_assert(!SOPC_strtoint("128", strlen("128"), 8, &a));
/* 16 */
ck_assert(SOPC_strtoint("0", strlen("0"), 16, &b));
ck_assert(0 == b);
ck_assert(SOPC_strtoint("42", strlen("42"), 16, &b));
ck_assert(42 == b);
ck_assert(!SOPC_strtoint("", strlen(""), 16, &b));
ck_assert(!SOPC_strtoint(NULL, 0, 16, &b));
ck_assert(!SOPC_strtoint("42", strlen("42"), 16, NULL));
ck_assert(SOPC_strtoint("-128", strlen("-128"), 16, &b));
ck_assert(INT8_MIN == b);
ck_assert(SOPC_strtoint("-129", strlen("-129"), 16, &b));
ck_assert(INT8_MIN - 1 == b);
ck_assert(SOPC_strtoint("127", strlen("127"), 16, &b));
ck_assert(INT8_MAX == b);
ck_assert(SOPC_strtoint("128", strlen("128"), 16, &b));
ck_assert(INT8_MAX + 1 == b);
ck_assert(SOPC_strtoint("-32768", strlen("-32768"), 16, &b));
ck_assert(INT16_MIN == b);
ck_assert(!SOPC_strtoint("-32769", strlen("-32769"), 16, &b));
ck_assert(SOPC_strtoint("32767", strlen("32767"), 16, &b));
ck_assert(INT16_MAX == b);
ck_assert(!SOPC_strtoint("32768", strlen("32768"), 16, &b));
/* 32 */
ck_assert(SOPC_strtoint("0", strlen("0"), 32, &c));
ck_assert(0 == c);
ck_assert(SOPC_strtoint("42", strlen("42"), 32, &c));
ck_assert(42 == c);
ck_assert(!SOPC_strtoint("", strlen(""), 32, &c));
ck_assert(!SOPC_strtoint(NULL, 0, 32, &c));
ck_assert(!SOPC_strtoint("42", strlen("42"), 32, NULL));
ck_assert(SOPC_strtoint("-128", strlen("-128"), 32, &c));
ck_assert(INT8_MIN == c);
ck_assert(SOPC_strtoint("-129", strlen("-129"), 32, &c));
ck_assert(INT8_MIN - 1 == c);
ck_assert(SOPC_strtoint("127", strlen("127"), 32, &c));
ck_assert(INT8_MAX == c);
ck_assert(SOPC_strtoint("128", strlen("128"), 32, &c));
ck_assert(INT8_MAX + 1 == c);
ck_assert(SOPC_strtoint("-32768", strlen("-32768"), 32, &c));
ck_assert(INT16_MIN == c);
ck_assert(SOPC_strtoint("-32769", strlen("-32769"), 32, &c));
ck_assert(INT16_MIN - 1 == c);
ck_assert(SOPC_strtoint("32767", strlen("32767"), 32, &c));
ck_assert(INT16_MAX == c);
ck_assert(SOPC_strtoint("32768", strlen("32768"), 32, &c));
ck_assert(INT16_MAX + 1 == c);
ck_assert(SOPC_strtoint("-2147483648", strlen("-2147483648"), 32, &c));
ck_assert(INT32_MIN == c);
ck_assert(!SOPC_strtoint("-2147483649", strlen("-2147483649"), 32, &c));
ck_assert(SOPC_strtoint("2147483647", strlen("2147483647"), 32, &c));
ck_assert(INT32_MAX == c);
ck_assert(!SOPC_strtoint("2147483648", strlen("2147483648"), 32, &c));
/* 64 */
ck_assert(SOPC_strtoint("0", strlen("0"), 64, &d));
ck_assert(0 == d);
ck_assert(SOPC_strtoint("42", strlen("42"), 64, &d));
ck_assert(42 == d);
ck_assert(!SOPC_strtoint("", strlen(""), 64, &d));
ck_assert(!SOPC_strtoint(NULL, 0, 64, &d));
ck_assert(!SOPC_strtoint("42", strlen("42"), 64, NULL));
ck_assert(SOPC_strtoint("-128", strlen("-128"), 64, &d));
ck_assert(INT8_MIN == d);
ck_assert(SOPC_strtoint("-129", strlen("-129"), 64, &d));
ck_assert(INT8_MIN - 1 == d);
ck_assert(SOPC_strtoint("127", strlen("127"), 64, &d));
ck_assert(INT8_MAX == d);
ck_assert(SOPC_strtoint("128", strlen("128"), 64, &d));
ck_assert(INT8_MAX + 1 == d);
ck_assert(SOPC_strtoint("-32768", strlen("-32768"), 64, &d));
ck_assert(INT16_MIN == d);
ck_assert(SOPC_strtoint("-32769", strlen("-32769"), 64, &d));
ck_assert(INT16_MIN - 1 == d);
ck_assert(SOPC_strtoint("32767", strlen("32767"), 64, &d));
ck_assert(INT16_MAX == d);
ck_assert(SOPC_strtoint("32768", strlen("32768"), 64, &d));
ck_assert(INT16_MAX + 1 == d);
ck_assert(SOPC_strtoint("-2147483648", strlen("-2147483648"), 64, &d));
ck_assert(INT32_MIN == d);
ck_assert(SOPC_strtoint("-2147483649", strlen("-2147483649"), 64, &d));
ck_assert(-2147483649LL == d);
ck_assert(SOPC_strtoint("2147483647", strlen("2147483647"), 64, &d));
ck_assert(INT32_MAX == d);
ck_assert(SOPC_strtoint("2147483648", strlen("2147483648"), 64, &d));
ck_assert(2147483648LL == d);
ck_assert(SOPC_strtoint("-9223372036854775808", strlen("-9223372036854775808"), 64, &d));
ck_assert(INT64_MIN == d);
ck_assert(!SOPC_strtoint("-9223372036854775809", strlen("-9223372036854775809"), 64, &d));
ck_assert(SOPC_strtoint("9223372036854775807", strlen("9223372036854775807"), 64, &d));
ck_assert(INT64_MAX == d);
ck_assert(!SOPC_strtoint("9223372036854775808", strlen("9223372036854775808"), 64, &d));
}
END_TEST
START_TEST(test_string_nodeid)
{
SOPC_NodeId nid;
......@@ -4306,6 +4555,8 @@ Suite* tests_make_suite_tools(void)
tcase_add_test(tc_basetools, test_strcmp_ignore_case_alt_end);
tcase_add_test(tc_basetools, test_helper_uri);
tcase_add_test(tc_basetools, test_strtouint);
tcase_add_test(tc_basetools, test_strtouint2);
tcase_add_test(tc_basetools, test_strtoint);
tcase_add_test(tc_basetools, test_string_nodeid);
suite_add_tcase(s, tc_basetools);
tc_buffer = tcase_create("Buffer");
......