From bd5b1ed713506d365793c7f9cb49d506ce392e7a Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Thu, 17 Nov 2011 13:55:11 -0500
Subject: [PATCH] LLSD-14: Make dumpStats()/calcStats() implementation more
 robust per Monty code review

---
 indra/llcommon/llsd.cpp | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/indra/llcommon/llsd.cpp b/indra/llcommon/llsd.cpp
index b0801745d7b..39d1f3e35f0 100644
--- a/indra/llcommon/llsd.cpp
+++ b/indra/llcommon/llsd.cpp
@@ -732,10 +732,10 @@ const LLSD& LLSD::Impl::undef()
 void LLSD::Impl::dumpStats() const
 {
 	S32 type_counts[LLSD::TypeLLSDNumTypes + 1];
-	memset(&type_counts, 0, LLSD::TypeLLSDNumTypes * sizeof(S32));
+	memset(&type_counts, 0, sizeof(type_counts));
 
 	S32 share_counts[LLSD::TypeLLSDNumTypes + 1];
-	memset(&share_counts, 0, LLSD::TypeLLSDNumTypes * sizeof(S32));
+	memset(&share_counts, 0, sizeof(share_counts));
 
 	// Add info from all the values this object has
 	calcStats(type_counts, share_counts);
@@ -753,11 +753,15 @@ void LLSD::Impl::dumpStats() const
 
 
 void LLSD::Impl::calcStats(S32 type_counts[], S32 share_counts[]) const
-{ 
-	type_counts[(S32) type()]++;	
-	if (shared())
+{
+	S32 type = S32(type());
+	if (0 <= type && type < LLSD::TypeLLSDNumTypes)
 	{
-		share_counts[(S32) type()]++;
+		type_counts[type]++;	
+		if (shared())
+		{
+			share_counts[type]++;
+		}
 	}
 }
 
-- 
GitLab