From 43f3888dc14c81fa8f6b917c2a3acce342e09b2f Mon Sep 17 00:00:00 2001
From: "arseny.kapoulkine@gmail.com"
 <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640>
Date: Thu, 8 Nov 2012 16:01:23 +0000
Subject: [PATCH] Fix undefined pointer arithmetic for reverse() and unique()
 in case the range is empty (begin == end)

git-svn-id: http://pugixml.googlecode.com/svn/trunk@926 99668b35-9821-0410-8761-19e4c4f06640
---
 src/pugixml.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index 1422eb0f..da6d447f 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -5479,13 +5479,13 @@ PUGI__NS_BEGIN
 
 	template <typename I> void reverse(I begin, I end)
 	{
-		while (begin + 1 < end) swap(*begin++, *--end);
+		while (end - begin > 1) swap(*begin++, *--end);
 	}
 
 	template <typename I> I unique(I begin, I end)
 	{
 		// fast skip head
-		while (begin + 1 < end && *begin != *(begin + 1)) begin++;
+		while (end - begin > 1 && *begin != *(begin + 1)) begin++;
 
 		if (begin == end) return begin;
 
-- 
GitLab