Skip to content

Commit

Permalink
dbus: Always append valid bool values
Browse files Browse the repository at this point in the history
D-Bus spec says bool values other than 1 and 0 are invalid.
Although C++'s int->bool conversion converts all values other than 0 to
1, it's still possible to create bool variables with values other than 1
and 0.
For example, when a variable is uninitialized, or with code like this:
  bool b;
  reinterpret_cast<int&>(b) = 10;

BUG=767024
TEST=dbus_unittests

Change-Id: I225456cb2662cffe992231f8f38a5add0dd2c250
Reviewed-on: https://chromium-review.googlesource.com/678537
Reviewed-by: Dan Erat <derat@chromium.org>
Commit-Queue: Ryo Hashimoto <hashimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#503995}
  • Loading branch information
Ryo Hashimoto authored and Commit Bot committed Sep 25, 2017
1 parent 4ec2824 commit 9dbc169
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion dbus/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ void MessageWriter::AppendBool(bool value) {
// dbus_message_iter_append_basic() used in AppendBasic() expects four
// bytes for DBUS_TYPE_BOOLEAN, so we must pass a dbus_bool_t, instead
// of a bool, to AppendBasic().
dbus_bool_t dbus_value = value;
dbus_bool_t dbus_value = value ? 1 : 0;
AppendBasic(DBUS_TYPE_BOOLEAN, &dbus_value);
}

Expand Down

0 comments on commit 9dbc169

Please sign in to comment.