From: Marcus Comstedt Date: Sun, 1 Nov 2015 14:58:00 +0000 (+0100) Subject: Revert "Java: Avoid dangerous writes via casted pointers" X-Git-Tag: libsigrok-0.4.0~131 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=32fd1edc2333b78c671afd3fc1f87a1bce925bd1;p=libsigrok.git Revert "Java: Avoid dangerous writes via casted pointers" This reverts commit 865de99391194e45a0e80ea534fc5e27d5287925. This fixes bug #688. --- diff --git a/bindings/java/org/sigrok/core/classes/classes.i b/bindings/java/org/sigrok/core/classes/classes.i index 7a61bfd5..5a020d7e 100644 --- a/bindings/java/org/sigrok/core/classes/classes.i +++ b/bindings/java/org/sigrok/core/classes/classes.i @@ -75,7 +75,7 @@ namespace Glib { jlong value; for (auto entry : $1) { - value = reinterpret_cast(new CValue(entry)); + *(CValue **) &value = new CValue(entry); jenv->CallObjectMethod($result, Vector_add, jenv->NewObject(Value, Value_init, value, true)); } @@ -149,7 +149,8 @@ MAP_COMMON(std::string, std::shared_ptr, String, ClassName) jlong value; for (auto entry : $1) { - value = reinterpret_cast(new std::shared_ptr< sigrok::ClassName>(entry.second)); + *(std::shared_ptr< sigrok::ClassName > **)&value = + new std::shared_ptr< sigrok::ClassName>(entry.second); jenv->CallObjectMethod($result, HashMap_put, jenv->NewStringUTF(entry.first.c_str()), jenv->NewObject(Value, Value_init, value, true)); @@ -184,8 +185,8 @@ MAP_COMMON(const sigrok::ConfigKey *, Glib::VariantBase, ConfigKey, Variant) jlong value; for (auto entry : $1) { - key = reinterpret_cast(entry.first); - value = reinterpret_cast(new Glib::VariantBase(entry.second)); + *(const sigrok::ConfigKey **) &key = entry.first; + *(Glib::VariantBase **) &value = new Glib::VariantBase(entry.second); jenv->CallObjectMethod($result, HashMap_put, jenv->NewObject(ConfigKey, ConfigKey_init, key, false)); jenv->NewObject(Variant, Variant_init, value, true)); @@ -219,7 +220,7 @@ MAP_COMMON(const sigrok::ConfigKey *, std::set, jlong key; for (auto map_entry : $1) { - key = reinterpret_cast(map_entry.first); + *(const sigrok::ConfigKey **) &key = map_entry.first; jobject value = jenv->NewObject(HashSet, HashSet_init); for (auto &set_entry : map_entry.second) jenv->CallObjectMethod(value, HashSet_add, @@ -267,7 +268,7 @@ typedef jobject jlogcallback; std::string message) { jlong loglevel_addr; - loglevel_addr = reinterpret_cast(loglevel); + *(const sigrok::LogLevel **) &loglevel_addr = loglevel; jobject loglevel_obj = env->NewObject( LogLevel, LogLevel_init, loglevel_addr, false); jobject message_obj = env->NewStringUTF(message.c_str()); @@ -313,8 +314,10 @@ typedef jobject jdatafeedcallback; { jlong device_addr; jlong packet_addr; - device_addr = reinterpret_cast(new std::shared_ptr(device)); - packet_addr = reinterpret_cast(new std::shared_ptr(packet)); + *(std::shared_ptr **) &device_addr = + new std::shared_ptr(device); + *(std::shared_ptr **) &packet_addr = + new std::shared_ptr(packet); jobject device_obj = env->NewObject( Device, Device_init, device_addr, true); jobject packet_obj = env->NewObject(