summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2018-11-09 10:03:50 (GMT)
committerEdwin Mons <edwin.mons@isode.com>2018-11-14 14:17:46 (GMT)
commitc7ad127218e3901e0006e75aa7e1399b449a845e (patch)
tree4371fe826528a5ad08cc036a09b375b51dfdce32
parent5d7fc97148125584a44a39a4beee1e71d9518385 (diff)
downloadswift-c7ad127218e3901e0006e75aa7e1399b449a845e.zip
swift-c7ad127218e3901e0006e75aa7e1399b449a845e.tar.bz2
Remove numeric_casts from BOSH parser
The two uses of numeric_casts have been rewritten as static casts, with asserts to guarantee (and inform the developer) that the number is never negative (code inspection showed that this should never be the case). Test-Information: Unit tests pass on macOS and Debian Change-Id: I3ca63724721ecd8e351d9017e0975b6ae326f85f
-rw-r--r--Swiften/Parser/BOSHBodyExtractor.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/Swiften/Parser/BOSHBodyExtractor.cpp b/Swiften/Parser/BOSHBodyExtractor.cpp
index c45d338..ff56792 100644
--- a/Swiften/Parser/BOSHBodyExtractor.cpp
+++ b/Swiften/Parser/BOSHBodyExtractor.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2011-2016 Isode Limited. 2 * Copyright (c) 2011-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 */
@@ -8,8 +8,6 @@
8 8
9#include <memory> 9#include <memory>
10 10
11#include <boost/numeric/conversion/cast.hpp>
12
13#include <Swiften/Parser/XMLParser.h> 11#include <Swiften/Parser/XMLParser.h>
14#include <Swiften/Parser/XMLParserClient.h> 12#include <Swiften/Parser/XMLParserClient.h>
15#include <Swiften/Parser/XMLParserFactory.h> 13#include <Swiften/Parser/XMLParserFactory.h>
@@ -119,17 +117,19 @@ BOSHBodyExtractor::BOSHBodyExtractor(XMLParserFactory* parserFactory, const Byte
119 117
120 body = BOSHBody(); 118 body = BOSHBody();
121 if (!endElementSeen) { 119 if (!endElementSeen) {
120 assert(i <= j.base());
122 body->content = std::string( 121 body->content = std::string(
123 reinterpret_cast<const char*>(vecptr(data) + std::distance(data.begin(), i)), 122 reinterpret_cast<const char*>(vecptr(data) + std::distance(data.begin(), i)),
124 boost::numeric_cast<size_t>(std::distance(i, j.base()))); 123 static_cast<size_t>(std::distance(i, j.base())));
125 } 124 }
126 125
127 // Parse the body element 126 // Parse the body element
128 BOSHBodyParserClient parserClient(this); 127 BOSHBodyParserClient parserClient(this);
129 std::shared_ptr<XMLParser> parser(parserFactory->createXMLParser(&parserClient)); 128 std::shared_ptr<XMLParser> parser(parserFactory->createXMLParser(&parserClient));
129 assert(data.begin() <= i);
130 if (!parser->parse(std::string( 130 if (!parser->parse(std::string(
131 reinterpret_cast<const char*>(vecptr(data)), 131 reinterpret_cast<const char*>(vecptr(data)),
132 boost::numeric_cast<size_t>(std::distance(data.begin(), i))))) { 132 static_cast<size_t>(std::distance(data.begin(), i))))) {
133 /* TODO: This needs to be only validating the BOSH <body> element, so that XMPP parsing errors are caught at 133 /* TODO: This needs to be only validating the BOSH <body> element, so that XMPP parsing errors are caught at
134 the correct higher layer */ 134 the correct higher layer */
135 body = boost::optional<BOSHBody>(); 135 body = boost::optional<BOSHBody>();