From e430b2e770be05fec6129dbd817e05cdbeaab622 Mon Sep 17 00:00:00 2001
From: Ger van Diepen <diepen@astron.nl>
Date: Mon, 30 Apr 2007 01:28:44 +0000
Subject: [PATCH] BugID: 1062 Fixed empty vector access problem found by
 -D_GLIBCXX_DEBUG.

---
 LCS/Blob/include/Blob/BlobIBufVector.h |  5 +++--
 LCS/Blob/include/Blob/BlobOBufVector.h | 12 +++++++-----
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/LCS/Blob/include/Blob/BlobIBufVector.h b/LCS/Blob/include/Blob/BlobIBufVector.h
index 3b8dc272272..4c484492e92 100644
--- a/LCS/Blob/include/Blob/BlobIBufVector.h
+++ b/LCS/Blob/include/Blob/BlobIBufVector.h
@@ -43,8 +43,9 @@ namespace LOFAR {
     public:
       // Construct from a vector.
       explicit BlobIBufVector (const std::vector<T>& buffer)
-	: BlobIBufChar(&buffer[0], buffer.size()*sizeof(T))
-	{}
+	: BlobIBufChar(buffer.empty()  ?  0 : &(buffer[0]),
+		       buffer.size()*sizeof(T))
+      {}
       
       // Destructor.
       virtual ~BlobIBufVector()
diff --git a/LCS/Blob/include/Blob/BlobOBufVector.h b/LCS/Blob/include/Blob/BlobOBufVector.h
index 4e48323f999..177ccd72cbf 100644
--- a/LCS/Blob/include/Blob/BlobOBufVector.h
+++ b/LCS/Blob/include/Blob/BlobOBufVector.h
@@ -53,12 +53,12 @@ namespace LOFAR {
       // not be deleted before this object.
       explicit BlobOBufVector (std::vector<T>& buffer,
 			       uint expandSize=1024, uint start=0)
-	: BlobOBufChar(&buffer[0], buffer.capacity(),
-		       expandSize, start, false),
-	itsVector (&buffer)
+	: BlobOBufChar(buffer.empty()  ?  0 : &(buffer[0]),
+		       buffer.capacity(), expandSize, start, false),
+	  itsVector   (&buffer)
 	{
 	  ASSERT(sizeof(T)==1);
-	  ASSERT(start <= buffer.size());
+          ASSERT(start <= buffer.size());
 	}
       
       // Destructor.
@@ -71,9 +71,11 @@ namespace LOFAR {
 	{
 	  if (newReservedSize > itsVector->capacity()) {
 	    itsVector->reserve (newReservedSize);
-	    setBuffer (&((*itsVector)[0]));
 	  }
 	  itsVector->resize (newSize);
+	  if (newSize > 0) {
+	    setBuffer (&((*itsVector)[0]));
+	  }
 	}
       
       std::vector<T>* itsVector;
-- 
GitLab