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 <j@w1.fi>
This commit is contained in:
Jouni Malinen 2014-12-31 16:40:14 +02:00
parent 19d4dab759
commit f11e797d4c
1 changed files with 1 additions and 0 deletions

View 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;