From 31177b000157a07480049a6d726650eb7c827d36 Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Mon, 5 Feb 2018 13:48:16 +0100
Subject: [PATCH] [SecureElement][NFC][Messageport] Fixing casting problems
[Bug] Casting double -> char should not be done directly.
[Verification] Passing values greater than 127 to API makes that
values are correctly translated.
TCT passrate 100%.
Change-Id: I786392fd3be2e7d0eb5211e224a25c8078f383e9
Signed-off-by: Piotr Kosko
---
src/messageport/messageport_instance.cc | 4 ++--
src/nfc/nfc_message_utils.cc | 12 ++++++------
src/secureelement/secureelement_instance.cc | 6 +++---
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/messageport/messageport_instance.cc b/src/messageport/messageport_instance.cc
index 2614fda..28df499 100644
--- a/src/messageport/messageport_instance.cc
+++ b/src/messageport/messageport_instance.cc
@@ -403,7 +403,7 @@ void MessageportInstance::RemoteMessagePortSendmessage(const picojson::value& ar
size_t i = 0;
for (auto iter = value_array.begin(); iter != value_array.end(); ++iter, ++i) {
- arr[i] = static_cast((*iter).get());
+ arr[i] = (int)(*iter).get();
}
bundle_add_byte(bundle, (*it).get("key").to_str().c_str(), arr, size);
delete[] arr;
@@ -421,7 +421,7 @@ void MessageportInstance::RemoteMessagePortSendmessage(const picojson::value& ar
size_t j = 0;
for (auto byteIter = byteStream.begin(); byteIter != byteStream.end(); ++byteIter, ++j) {
- arr[j] = static_cast((*byteIter).get());
+ arr[j] = (int)(*byteIter).get();
}
bundle_set_byte_array_element(bundle, (*it).get("key").to_str().c_str(), i, arr,
diff --git a/src/nfc/nfc_message_utils.cc b/src/nfc/nfc_message_utils.cc
index 4581c5e..1e36a2f 100644
--- a/src/nfc/nfc_message_utils.cc
+++ b/src/nfc/nfc_message_utils.cc
@@ -301,7 +301,7 @@ PlatformResult NFCMessageUtils::ReportNDEFMessage(const picojson::value& args,
std::unique_ptr data(new unsigned char[size]);
for (ssize_t i = 0; i < size; i++) {
- data[i] = static_cast(raw_data[i].get());
+ data[i] = (int)raw_data[i].get();
}
return ReportNdefMessageFromData(data.get(), size, out);
@@ -321,19 +321,19 @@ static PlatformResult NdefRecordGetHandle(picojson::value& record,
auto type_size = type_data.size();
std::unique_ptr type(new unsigned char[type_size]);
for (size_t i = 0; i < type_size; i++) {
- type[i] = static_cast(type_data[i].get());
+ type[i] = (int)type_data[i].get();
}
const picojson::array& id_data = FromJson(record_obj, "id");
auto id_size = id_data.size();
std::unique_ptr id(new unsigned char[id_size]);
for (size_t i = 0; i < id_size; i++) {
- id[i] = static_cast(id_data[i].get());
+ id[i] = (int)(id_data[i].get());
}
const picojson::array& payload_data = FromJson(record_obj, "payload");
auto payload_size = payload_data.size();
std::unique_ptr payload(new unsigned char[payload_size]);
for (size_t i = 0; i < payload_size; i++) {
- payload[i] = static_cast(payload_data[i].get());
+ payload[i] = (int)payload_data[i].get();
}
if ((tnf_from_json < TNF_MIN) || (tnf_from_json > TNF_MAX)) {
return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR, "Type mismatch", ("Not supported TNF"));
@@ -531,7 +531,7 @@ PlatformResult NFCMessageUtils::ReportNDEFRecord(const picojson::value& args,
std::unique_ptr data(new unsigned char[size]);
for (ssize_t i = 0; i < size; i++) {
- data[i] = static_cast(raw_data[i].get());
+ data[i] = (int)raw_data[i].get();
}
nfc_ndef_message_h message_handle = NULL;
@@ -900,7 +900,7 @@ PlatformResult NFCMessageUtils::ReportNDEFRecordMedia(const picojson::value& arg
std::unique_ptr data(new unsigned char[size]);
for (ssize_t i = 0; i < size; i++) {
- data[i] = static_cast(raw_data[i].get());
+ data[i] = (int)raw_data[i].get();
}
nfc_ndef_record_h handle = NULL;
diff --git a/src/secureelement/secureelement_instance.cc b/src/secureelement/secureelement_instance.cc
index ac4139a..7313d70 100644
--- a/src/secureelement/secureelement_instance.cc
+++ b/src/secureelement/secureelement_instance.cc
@@ -378,7 +378,7 @@ TizenResult SecureElementInstance::OpenBasicChannel(picojson::object const& args
};
for (size_t i = 0; i < v_aid_size; i++) {
- aid[i] = static_cast(v_aid[i].get());
+ aid[i] = (int)v_aid[i].get();
}
int ret = smartcard_session_open_basic_channel(session, aid, v_aid_size, P2, &channel);
@@ -423,7 +423,7 @@ TizenResult SecureElementInstance::OpenLogicalChannel(picojson::object const& ar
};
for (size_t i = 0; i < v_aid_size; i++) {
- aid[i] = static_cast(v_aid[i].get());
+ aid[i] = (int)v_aid[i].get();
}
int ret = smartcard_session_open_logical_channel(session, aid, v_aid_size, P2, &channel);
@@ -554,7 +554,7 @@ TizenResult SecureElementInstance::Transmit(picojson::object const& args,
};
for (size_t i = 0; i < v_cmd_size; i++) {
- cmd[i] = static_cast(v_cmd[i].get());
+ cmd[i] = (int) v_cmd[i].get();
}
int length = 0;
--
2.7.4