]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
D-Bus: Avoid valgrind warning due to compiler optimization
authorJouni Malinen <j@w1.fi>
Wed, 31 Dec 2014 14:40:14 +0000 (16:40 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 2 Jan 2015 20:50:26 +0000 (22:50 +0200)
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 <j@w1.fi>
wpa_supplicant/dbus/dbus_dict_helpers.c

index 0020a85247fabf1e04bf0f83508c1c2e29841e2f..4a2996aaef29fc674842325646ff9b0e2b27b617 100644 (file)
@@ -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;