summaryrefslogtreecommitdiffstats
path: root/dbus
diff options
context:
space:
mode:
Diffstat (limited to 'dbus')
-rw-r--r--dbus/message.cc8
-rw-r--r--dbus/message_unittest.cc15
2 files changed, 22 insertions, 1 deletions
diff --git a/dbus/message.cc b/dbus/message.cc
index aa9cc55..2750cb1 100644
--- a/dbus/message.cc
+++ b/dbus/message.cc
@@ -755,6 +755,12 @@ bool MessageReader::PopArrayOfBytes(uint8** bytes, size_t* length) {
MessageReader array_reader(message_);
if (!PopArray(&array_reader))
return false;
+ // An empty array is allowed.
+ if (!array_reader.HasMoreData()) {
+ *length = 0;
+ *bytes = NULL;
+ return true;
+ }
if (!array_reader.CheckDataType(DBUS_TYPE_BYTE))
return false;
int int_length = 0;
@@ -762,7 +768,7 @@ bool MessageReader::PopArrayOfBytes(uint8** bytes, size_t* length) {
bytes,
&int_length);
*length = static_cast<int>(int_length);
- return bytes != NULL;
+ return true;
}
bool MessageReader::PopArrayOfStrings(
diff --git a/dbus/message_unittest.cc b/dbus/message_unittest.cc
index 29fe888..9c76b0d 100644
--- a/dbus/message_unittest.cc
+++ b/dbus/message_unittest.cc
@@ -171,6 +171,21 @@ TEST(MessageTest, ArrayOfBytes) {
EXPECT_EQ(3, output_bytes[2]);
}
+TEST(MessageTest, ArrayOfBytes_Empty) {
+ scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty());
+ dbus::MessageWriter writer(message.get());
+ std::vector<uint8> bytes;
+ writer.AppendArrayOfBytes(bytes.data(), bytes.size());
+
+ dbus::MessageReader reader(message.get());
+ uint8* output_bytes = NULL;
+ size_t length = 0;
+ ASSERT_TRUE(reader.PopArrayOfBytes(&output_bytes, &length));
+ ASSERT_FALSE(reader.HasMoreData());
+ ASSERT_EQ(0U, length);
+ EXPECT_EQ(NULL, output_bytes);
+}
+
TEST(MessageTest, ArrayOfStrings) {
scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty());
dbus::MessageWriter writer(message.get());