From: Michal Bistyga Date: Fri, 2 Feb 2018 11:37:08 +0000 (+0100) Subject: [Bluetooth] Fixing undefined behaviour during cast X-Git-Tag: submit/tizen_3.0/20180205.082857~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ba2505210e9d1b649802676a8791f87e6d474c90;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Bluetooth] Fixing undefined behaviour during cast Char is unsigned by default on ARM architecture. static_cast from double to unsigned char is undefined behaviour and complier overwritten any negative value with 0. [Validation] tests 100% pass rate Change-Id: Iec39a3c17b18ec7aa4f020fe5de709d66fa426fd Signed-off-by: Michal Bistyga --- diff --git a/src/bluetooth/bluetooth_gatt_service.cc b/src/bluetooth/bluetooth_gatt_service.cc index 14f4bc70..f6798a89 100644 --- a/src/bluetooth/bluetooth_gatt_service.cc +++ b/src/bluetooth/bluetooth_gatt_service.cc @@ -424,7 +424,7 @@ void BluetoothGATTService::WriteValue(const picojson::value& args, picojson::obj int value_size = value_array.size(); std::unique_ptr value_data(new char[value_size]); for (int i = 0; i < value_size; ++i) { - value_data[i] = static_cast(value_array[i].get()); + value_data[i] = (int) value_array[i].get(); } struct Data { diff --git a/src/bluetooth/bluetooth_health_channel.cc b/src/bluetooth/bluetooth_health_channel.cc index 8d192791..e1196935 100644 --- a/src/bluetooth/bluetooth_health_channel.cc +++ b/src/bluetooth/bluetooth_health_channel.cc @@ -77,7 +77,7 @@ void BluetoothHealthChannel::SendData(const picojson::value& data, picojson::obj std::unique_ptr data_ptr{new char[data_size]}; for (std::size_t i = 0; i < data_size; ++i) { - data_ptr[i] = static_cast(binary_data[i].get()); + data_ptr[i] = (int) binary_data[i].get(); } int ntv_ret = bt_hdp_send_data(channel, data_ptr.get(), data_size); diff --git a/src/bluetooth/bluetooth_socket.cc b/src/bluetooth/bluetooth_socket.cc index 7625ae4e..fea9ed18 100644 --- a/src/bluetooth/bluetooth_socket.cc +++ b/src/bluetooth/bluetooth_socket.cc @@ -63,7 +63,7 @@ void BluetoothSocket::WriteData(const picojson::value& data, picojson::object& o std::unique_ptr data_ptr{new char[data_size]}; for (std::size_t i = 0; i < data_size; ++i) { - data_ptr[i] = static_cast(binary_data[i].get()); + data_ptr[i] = (int) binary_data[i].get(); } if (kBluetoothError == bt_socket_send_data(socket, data_ptr.get(), data_size)) {