[SecureElement][NFC][Messageport] Fixing casting problems 69/169369/1 accepted/tizen/3.0/common/20180219.092234 accepted/tizen/3.0/mobile/20180219.000616 accepted/tizen/3.0/tv/20180219.000536 accepted/tizen/3.0/wearable/20180219.000541 submit/tizen_3.0/20180207.065225
authorPiotr Kosko <p.kosko@samsung.com>
Mon, 5 Feb 2018 12:48:16 +0000 (13:48 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Mon, 5 Feb 2018 13:43:04 +0000 (14:43 +0100)
[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 <p.kosko@samsung.com>
src/messageport/messageport_instance.cc
src/nfc/nfc_message_utils.cc
src/secureelement/secureelement_instance.cc

index 2614fda..28df499 100644 (file)
@@ -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<unsigned char>((*iter).get<double>());
+        arr[i] = (int)(*iter).get<double>();
       }
       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<unsigned char>((*byteIter).get<double>());
+          arr[j] = (int)(*byteIter).get<double>();
         }
 
         bundle_set_byte_array_element(bundle, (*it).get("key").to_str().c_str(), i, arr,
index 4581c5e..1e36a2f 100644 (file)
@@ -301,7 +301,7 @@ PlatformResult NFCMessageUtils::ReportNDEFMessage(const picojson::value& args,
   std::unique_ptr<unsigned char[]> data(new unsigned char[size]);
 
   for (ssize_t i = 0; i < size; i++) {
-    data[i] = static_cast<unsigned char>(raw_data[i].get<double>());
+    data[i] = (int)raw_data[i].get<double>();
   }
 
   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<unsigned char[]> type(new unsigned char[type_size]);
   for (size_t i = 0; i < type_size; i++) {
-    type[i] = static_cast<unsigned char>(type_data[i].get<double>());
+    type[i] = (int)type_data[i].get<double>();
   }
   const picojson::array& id_data = FromJson<picojson::array>(record_obj, "id");
   auto id_size = id_data.size();
   std::unique_ptr<unsigned char[]> id(new unsigned char[id_size]);
   for (size_t i = 0; i < id_size; i++) {
-    id[i] = static_cast<unsigned char>(id_data[i].get<double>());
+    id[i] = (int)(id_data[i].get<double>());
   }
   const picojson::array& payload_data = FromJson<picojson::array>(record_obj, "payload");
   auto payload_size = payload_data.size();
   std::unique_ptr<unsigned char[]> payload(new unsigned char[payload_size]);
   for (size_t i = 0; i < payload_size; i++) {
-    payload[i] = static_cast<unsigned char>(payload_data[i].get<double>());
+    payload[i] = (int)payload_data[i].get<double>();
   }
   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<unsigned char[]> data(new unsigned char[size]);
 
   for (ssize_t i = 0; i < size; i++) {
-    data[i] = static_cast<unsigned char>(raw_data[i].get<double>());
+    data[i] = (int)raw_data[i].get<double>();
   }
   nfc_ndef_message_h message_handle = NULL;
 
@@ -900,7 +900,7 @@ PlatformResult NFCMessageUtils::ReportNDEFRecordMedia(const picojson::value& arg
 
   std::unique_ptr<unsigned char[]> data(new unsigned char[size]);
   for (ssize_t i = 0; i < size; i++) {
-    data[i] = static_cast<unsigned char>(raw_data[i].get<double>());
+    data[i] = (int)raw_data[i].get<double>();
   }
 
   nfc_ndef_record_h handle = NULL;
index ac4139a..7313d70 100644 (file)
@@ -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<unsigned char>(v_aid[i].get<double>());
+      aid[i] = (int)v_aid[i].get<double>();
     }
 
     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<unsigned char>(v_aid[i].get<double>());
+      aid[i] = (int)v_aid[i].get<double>();
     }
 
     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<unsigned char>(v_cmd[i].get<double>());
+      cmd[i] = (int) v_cmd[i].get<double>();
     }
 
     int length = 0;