mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
C2: Report copied buffer lengths
This commit is contained in:
committed by
Kyle Schwarz
parent
7a5c8c2879
commit
aff547b738
@@ -465,11 +465,13 @@ icsneoc2_error_t icsneoc2_device_pcb_serial_get(const icsneoc2_device_t* device,
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
const auto& data = *pcbSerial;
|
||||
if(value) {
|
||||
size_t copyLen = std::min(*value_length, data.size());
|
||||
std::copy(data.begin(), data.begin() + copyLen, value);
|
||||
if(!value) {
|
||||
*value_length = data.size();
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
*value_length = data.size();
|
||||
size_t copyLen = std::min(*value_length, data.size());
|
||||
std::copy(data.begin(), data.begin() + copyLen, value);
|
||||
*value_length = copyLen;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
@@ -515,14 +517,16 @@ icsneoc2_error_t icsneoc2_mac_network_id_get(const icsneoc2_mac_addr_entry_t* ma
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_mac_address_get(const icsneoc2_mac_addr_entry_t* mac_address, uint8_t* value, size_t* value_length) {
|
||||
if(!mac_address || !value || !value_length) {
|
||||
if(!mac_address || !value_length) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
if(value) {
|
||||
size_t copyLen = std::min(*value_length, static_cast<size_t>(ICSNEO_MAC_ADDRESS_LEN));
|
||||
std::copy(mac_address->address, mac_address->address + copyLen, value);
|
||||
if(!value) {
|
||||
*value_length = static_cast<size_t>(ICSNEO_MAC_ADDRESS_LEN);
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
*value_length = static_cast<size_t>(ICSNEO_MAC_ADDRESS_LEN);
|
||||
size_t copyLen = std::min(*value_length, static_cast<size_t>(ICSNEO_MAC_ADDRESS_LEN));
|
||||
std::copy(mac_address->address, mac_address->address + copyLen, value);
|
||||
*value_length = copyLen;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
|
||||
@@ -127,6 +127,28 @@ TEST(icsneoc2, test_icsneoc2_device_is_valid)
|
||||
ASSERT_EQ(icsneoc2_error_invalid_parameters, icsneoc2_device_is_valid(NULL));
|
||||
}
|
||||
|
||||
TEST(icsneoc2, test_icsneoc2_mac_address_get_query_length)
|
||||
{
|
||||
icsneoc2_mac_addr_entry_t mac_address = {};
|
||||
size_t value_length = 0;
|
||||
|
||||
ASSERT_EQ(icsneoc2_error_success, icsneoc2_mac_address_get(&mac_address, NULL, &value_length));
|
||||
ASSERT_EQ(ICSNEO_MAC_ADDRESS_LEN, value_length);
|
||||
}
|
||||
|
||||
TEST(icsneoc2, test_icsneoc2_mac_address_get_truncated_length)
|
||||
{
|
||||
icsneoc2_mac_addr_entry_t mac_address = {};
|
||||
const uint8_t expected[ICSNEO_MAC_ADDRESS_LEN] = {0x00, 0xFC, 0x70, 0x1E, 0x18, 0x70};
|
||||
std::copy(std::begin(expected), std::end(expected), mac_address.address);
|
||||
|
||||
uint8_t value[3] = {};
|
||||
size_t value_length = sizeof(value);
|
||||
ASSERT_EQ(icsneoc2_error_success, icsneoc2_mac_address_get(&mac_address, value, &value_length));
|
||||
ASSERT_EQ(sizeof(value), value_length);
|
||||
ASSERT_EQ(0, memcmp(expected, value, sizeof(value)));
|
||||
}
|
||||
|
||||
TEST(icsneoc2, test_icsneoc2_error_invalid_parameters_and_invalid_device)
|
||||
{
|
||||
bool placeholderBool = false;
|
||||
|
||||
Reference in New Issue
Block a user