From c7ad127218e3901e0006e75aa7e1399b449a845e Mon Sep 17 00:00:00 2001
From: Edwin Mons <edwin.mons@isode.com>
Date: Fri, 9 Nov 2018 11:03:50 +0100
Subject: 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

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 @@
 /*
- * Copyright (c) 2011-2016 Isode Limited.
+ * Copyright (c) 2011-2018 Isode Limited.
  * All rights reserved.
  * See the COPYING file for more information.
  */
@@ -8,8 +8,6 @@
 
 #include <memory>
 
-#include <boost/numeric/conversion/cast.hpp>
-
 #include <Swiften/Parser/XMLParser.h>
 #include <Swiften/Parser/XMLParserClient.h>
 #include <Swiften/Parser/XMLParserFactory.h>
@@ -119,17 +117,19 @@ BOSHBodyExtractor::BOSHBodyExtractor(XMLParserFactory* parserFactory, const Byte
 
     body = BOSHBody();
     if (!endElementSeen) {
+        assert(i <= j.base());
         body->content = std::string(
                 reinterpret_cast<const char*>(vecptr(data) + std::distance(data.begin(), i)),
-                boost::numeric_cast<size_t>(std::distance(i, j.base())));
+                static_cast<size_t>(std::distance(i, j.base())));
     }
 
     // Parse the body element
     BOSHBodyParserClient parserClient(this);
     std::shared_ptr<XMLParser> parser(parserFactory->createXMLParser(&parserClient));
+    assert(data.begin() <= i);
     if (!parser->parse(std::string(
             reinterpret_cast<const char*>(vecptr(data)),
-            boost::numeric_cast<size_t>(std::distance(data.begin(), i))))) {
+            static_cast<size_t>(std::distance(data.begin(), i))))) {
         /* TODO: This needs to be only validating the BOSH <body> element, so that XMPP parsing errors are caught at
            the correct higher layer */
         body = boost::optional<BOSHBody>();
-- 
cgit v0.10.2-6-g49f6