Fix the error of calling htole16/htole32/le16toh/le32toh method
libpldm is endian safe, fix the wrong usage in test case.
Change-Id: Iaa8816feda462a11fad098fe9a3074913ab367a3
Signed-off-by: Jolie Ku <jolie_ku@wistron.com>
diff --git a/libpldm/platform.c b/libpldm/platform.c
index 9c696fc..3f91ee9 100644
--- a/libpldm/platform.c
+++ b/libpldm/platform.c
@@ -925,9 +925,15 @@
PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2) {
return PLDM_ERROR_INVALID_LENGTH;
}
- memcpy(response->pending_and_present_values, pending_value, 2);
- memcpy(&response->pending_and_present_values[2], present_value,
- 2);
+ uint16_t val_pending = *(uint16_t *)pending_value;
+ val_pending = htole16(val_pending);
+ memcpy(response->pending_and_present_values, &val_pending,
+ sizeof(uint16_t));
+ uint16_t val_present = *(uint16_t *)present_value;
+ val_present = htole16(val_present);
+ memcpy(
+ (response->pending_and_present_values + sizeof(uint16_t)),
+ &val_present, sizeof(uint16_t));
} else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) {
@@ -935,9 +941,15 @@
PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6) {
return PLDM_ERROR_INVALID_LENGTH;
}
- memcpy(response->pending_and_present_values, pending_value, 4);
- memcpy(&response->pending_and_present_values[4], present_value,
- 4);
+ uint32_t val_pending = *(uint32_t *)pending_value;
+ val_pending = htole32(val_pending);
+ memcpy(response->pending_and_present_values, &val_pending,
+ sizeof(uint32_t));
+ uint32_t val_present = *(uint32_t *)present_value;
+ val_present = htole32(val_present);
+ memcpy(
+ (response->pending_and_present_values + sizeof(uint32_t)),
+ &val_present, sizeof(uint32_t));
}
return PLDM_SUCCESS;
}
@@ -1012,9 +1024,16 @@
PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2) {
return PLDM_ERROR_INVALID_LENGTH;
}
- memcpy(pending_value, response->pending_and_present_values, 2);
- memcpy(present_value, &response->pending_and_present_values[2],
- 2);
+ memcpy(pending_value, response->pending_and_present_values,
+ sizeof(uint16_t));
+ uint16_t *val_pending = (uint16_t *)pending_value;
+ *val_pending = le16toh(*val_pending);
+ memcpy(
+ present_value,
+ (response->pending_and_present_values + sizeof(uint16_t)),
+ sizeof(uint16_t));
+ uint16_t *val_present = (uint16_t *)present_value;
+ *val_present = le16toh(*val_present);
} else if (*effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
*effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) {
@@ -1022,9 +1041,16 @@
PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6) {
return PLDM_ERROR_INVALID_LENGTH;
}
- memcpy(pending_value, response->pending_and_present_values, 4);
- memcpy(present_value, &response->pending_and_present_values[4],
- 4);
+ memcpy(pending_value, response->pending_and_present_values,
+ sizeof(uint32_t));
+ uint32_t *val_pending = (uint32_t *)pending_value;
+ *val_pending = le32toh(*val_pending);
+ memcpy(
+ present_value,
+ (response->pending_and_present_values + sizeof(uint32_t)),
+ sizeof(uint32_t));
+ uint32_t *val_present = (uint32_t *)present_value;
+ *val_present = le32toh(*val_present);
}
return PLDM_SUCCESS;
}