From f11e797d4c4b26c8551de7b6926d015a16a1206e Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Wed, 31 Dec 2014 16:40:14 +0200 Subject: [PATCH] D-Bus: Avoid valgrind warning due to compiler optimization It looks like both gcc and clang optimize the (entry.type != foo || entry.array_type != bar) in a way that ends up evaluating the second condition even when the first one results in 0. While this is not really what the C language requirements on short-circuit evaluation require, the compiler likely assumes this can have no side effects and with both type and array_type being comparable in a single 64-bit operation, this can clearly be a bit more efficient. While the code behaves same in both cases, valgrind does warn about use of uninitialized memory when the second condition is evaluated (entry.array_type is not initialized if entry.type != DBUS_TYPE_ARRAY). To keep valgrind logs cleaner, initialize entry.array_type to DBUS_TYPE_INVALID so that these compiler optimizations do not result in reading uninitialized memory. Signed-off-by: Jouni Malinen --- wpa_supplicant/dbus/dbus_dict_helpers.c | 1 + 1 file changed, 1 insertion(+) diff --git a/wpa_supplicant/dbus/dbus_dict_helpers.c b/wpa_supplicant/dbus/dbus_dict_helpers.c index 0020a8524..4a2996aae 100644 --- a/wpa_supplicant/dbus/dbus_dict_helpers.c +++ b/wpa_supplicant/dbus/dbus_dict_helpers.c @@ -1039,6 +1039,7 @@ dbus_bool_t wpa_dbus_dict_get_entry(DBusMessageIter *iter_dict, dbus_message_iter_recurse(&iter_dict_entry, &iter_dict_val); entry->type = dbus_message_iter_get_arg_type(&iter_dict_val); + entry->array_type = DBUS_TYPE_INVALID; if (!_wpa_dbus_dict_fill_value_from_variant(entry, &iter_dict_val)) goto error;