From da26e1095118631ba7cefa21101a123ff5258647 Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <c.oelckers@zdoom.fake>
Date: Sat, 14 Mar 2015 09:34:55 +0100
Subject: [PATCH] - fixed: The FBoundingBox constructor taking a point and a
 radius needs to restrict the resulting values to the fixed point range.

---
 src/m_bbox.cpp | 21 +++++++++++++++++++++
 src/m_bbox.h   |  8 +-------
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/m_bbox.cpp b/src/m_bbox.cpp
index 199da8d68e..c73f47bc46 100644
--- a/src/m_bbox.cpp
+++ b/src/m_bbox.cpp
@@ -27,6 +27,27 @@
 #include "m_bbox.h"
 #include "p_local.h"
 
+//==========================================================================
+//
+//
+//
+//==========================================================================
+
+FBoundingBox::FBoundingBox(fixed_t x, fixed_t y, fixed_t radius)
+{
+	m_Box[BOXTOP] = (fixed_t)MIN<SQWORD>((SQWORD)y + radius, FIXED_MAX);
+	m_Box[BOXLEFT] = (fixed_t)MAX<SQWORD>((SQWORD)x - radius, FIXED_MIN);
+	m_Box[BOXRIGHT] = (fixed_t)MIN<SQWORD>((SQWORD)x + radius, FIXED_MAX);
+	m_Box[BOXBOTTOM] = (fixed_t)MAX<SQWORD>((SQWORD)y - radius, FIXED_MIN);
+}
+
+
+//==========================================================================
+//
+//
+//
+//==========================================================================
+
 void FBoundingBox::AddToBox (fixed_t x, fixed_t y)
 {
 	if (x < m_Box[BOXLEFT])
diff --git a/src/m_bbox.h b/src/m_bbox.h
index 256393d600..174cd6ecfb 100644
--- a/src/m_bbox.h
+++ b/src/m_bbox.h
@@ -43,13 +43,7 @@ public:
 		m_Box[BOXBOTTOM] = bottom;
 	}
 
-	FBoundingBox(fixed_t x, fixed_t y, fixed_t radius)
-	{
-		m_Box[BOXTOP] = y + radius;
-		m_Box[BOXLEFT] = x - radius;
-		m_Box[BOXRIGHT] = x + radius;
-		m_Box[BOXBOTTOM] = y - radius;
-	}
+	FBoundingBox(fixed_t x, fixed_t y, fixed_t radius);
 
 	void ClearBox ()
 	{