summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2018-11-09 10:04:04 (GMT)
committerEdwin Mons <edwin.mons@isode.com>2018-11-14 14:18:08 (GMT)
commitccad2debbf8d7322c9d2b517763d7b8e3902a828 (patch)
tree50054ea69dcf21179920ffdde5790908e48848d8 /Swiften/FileTransfer/ByteArrayReadBytestream.cpp
parentc7ad127218e3901e0006e75aa7e1399b449a845e (diff)
downloadswift-ccad2debbf8d7322c9d2b517763d7b8e3902a828.zip
swift-ccad2debbf8d7322c9d2b517763d7b8e3902a828.tar.bz2
Address bad_numeric_casts for filetransfers
The filetransfer blockSize is now an unsigned integer, as 0 could be used to denote an invalid block size as well (and indeed, already indicated that better than -1 did). All use of numeric_cast in filetransfer code has been fixed to deal with the possibility of thrown exceptions. Test-Information: Unit tests pass on macOS and Debian Change-Id: I1833d553bae071238be20ebc386ef602effb78b0
Diffstat (limited to 'Swiften/FileTransfer/ByteArrayReadBytestream.cpp')
-rw-r--r--Swiften/FileTransfer/ByteArrayReadBytestream.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/Swiften/FileTransfer/ByteArrayReadBytestream.cpp b/Swiften/FileTransfer/ByteArrayReadBytestream.cpp
index cd9fa4a..3fdff27 100644
--- a/Swiften/FileTransfer/ByteArrayReadBytestream.cpp
+++ b/Swiften/FileTransfer/ByteArrayReadBytestream.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2016 Isode Limited. 2 * Copyright (c) 2010-2018 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -19,13 +19,19 @@ std::shared_ptr<ByteArray> ByteArrayReadBytestream::read(size_t size) {
19 if (position + readSize > data.size()) { 19 if (position + readSize > data.size()) {
20 readSize = data.size() - position; 20 readSize = data.size() - position;
21 } 21 }
22 std::shared_ptr<ByteArray> result = std::make_shared<ByteArray>( 22 try {
23 data.begin() + boost::numeric_cast<long long>(position), 23 std::shared_ptr<ByteArray> result = std::make_shared<ByteArray>(
24 data.begin() + boost::numeric_cast<long long>(position) + boost::numeric_cast<long long>(readSize)); 24 data.begin() + boost::numeric_cast<long long>(position),
25 25 data.begin() + boost::numeric_cast<long long>(position) + boost::numeric_cast<long long>(readSize));
26 onRead(*result); 26 onRead(*result);
27 position += readSize; 27 position += readSize;
28 return result; 28 return result;
29 }
30 catch (const boost::numeric::bad_numeric_cast&) {
31 // If we cannot cast to long long, we probably ran out of memory long ago
32 assert(false);
33 return {};
34 }
29} 35}
30 36
31void ByteArrayReadBytestream::addData(const std::vector<unsigned char>& moreData) { 37void ByteArrayReadBytestream::addData(const std::vector<unsigned char>& moreData) {