diff --git a/src/lib/platform/XWindowsClipboard.cpp b/src/lib/platform/XWindowsClipboard.cpp index 4b779bce..1a5ea464 100644 --- a/src/lib/platform/XWindowsClipboard.cpp +++ b/src/lib/platform/XWindowsClipboard.cpp @@ -314,7 +314,10 @@ XWindowsClipboard::add(EFormat format, const String& data) bool XWindowsClipboard::open(Time time) const { - assert(!m_open); + if (m_open) { + return false; + LOG((CLOG_DEBUG "failed to open clipboard: already opened")); + } LOG((CLOG_DEBUG "open clipboard %d", m_id)); diff --git a/src/lib/synergy/IClipboard.cpp b/src/lib/synergy/IClipboard.cpp index 48982402..4af3802f 100644 --- a/src/lib/synergy/IClipboard.cpp +++ b/src/lib/synergy/IClipboard.cpp @@ -30,36 +30,37 @@ IClipboard::unmarshall(IClipboard* clipboard, const String& data, Time time) const char* index = data.data(); - // clear existing data - clipboard->open(time); - clipboard->empty(); + if (clipboard->open(time)) { + // clear existing data + clipboard->empty(); - // read the number of formats - const UInt32 numFormats = readUInt32(index); - index += 4; - - // read each format - for (UInt32 i = 0; i < numFormats; ++i) { - // get the format id - IClipboard::EFormat format = - static_cast(readUInt32(index)); + // read the number of formats + const UInt32 numFormats = readUInt32(index); index += 4; - // get the size of the format data - UInt32 size = readUInt32(index); - index += 4; + // read each format + for (UInt32 i = 0; i < numFormats; ++i) { + // get the format id + IClipboard::EFormat format = + static_cast(readUInt32(index)); + index += 4; - // save the data if it's a known format. if either the client - // or server supports more clipboard formats than the other - // then one of them will get a format >= kNumFormats here. - if (format add(format, String(index, size)); + // get the size of the format data + UInt32 size = readUInt32(index); + index += 4; + + // save the data if it's a known format. if either the client + // or server supports more clipboard formats than the other + // then one of them will get a format >= kNumFormats here. + if (format add(format, String(index, size)); + } + index += size; } - index += size; - } - // done - clipboard->close(); + // done + clipboard->close(); + } } String @@ -72,33 +73,34 @@ IClipboard::marshall(const IClipboard* clipboard) std::vector formatData; formatData.resize(IClipboard::kNumFormats); // FIXME -- use current time - clipboard->open(0); + if (clipboard->open(0)) { - // compute size of marshalled data - UInt32 size = 4; - UInt32 numFormats = 0; - for (UInt32 format = 0; format != IClipboard::kNumFormats; ++format) { - if (clipboard->has(static_cast(format))) { - ++numFormats; - formatData[format] = - clipboard->get(static_cast(format)); - size += 4 + 4 + (UInt32)formatData[format].size(); + // compute size of marshalled data + UInt32 size = 4; + UInt32 numFormats = 0; + for (UInt32 format = 0; format != IClipboard::kNumFormats; ++format) { + if (clipboard->has(static_cast(format))) { + ++numFormats; + formatData[format] = + clipboard->get(static_cast(format)); + size += 4 + 4 + (UInt32)formatData[format].size(); + } } - } - // allocate space - data.reserve(size); + // allocate space + data.reserve(size); - // marshall the data - writeUInt32(&data, numFormats); - for (UInt32 format = 0; format != IClipboard::kNumFormats; ++format) { - if (clipboard->has(static_cast(format))) { - writeUInt32(&data, format); - writeUInt32(&data, (UInt32)formatData[format].size()); - data += formatData[format]; + // marshall the data + writeUInt32(&data, numFormats); + for (UInt32 format = 0; format != IClipboard::kNumFormats; ++format) { + if (clipboard->has(static_cast(format))) { + writeUInt32(&data, format); + writeUInt32(&data, (UInt32)formatData[format].size()); + data += formatData[format]; + } } + clipboard->close(); } - clipboard->close(); return data; }