From 182743e67d2327d51af517fee6d48056793faeff Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Tue, 11 Oct 2016 14:06:28 +0200
Subject: [PATCH] Fixed problem with DD and zero atoms

When there are zero atoms in one of the DD domains,
some arrays are allocated to be zero sized and later
accessed with &array[0].

Whereas this is harmless, it triggers an out-of-boundary
error when plumed is compiled with --enable-debug-glibcxx

The size of those arrays is now guaranteed to be at least 1.
---
 src/core/Atoms.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/core/Atoms.cpp b/src/core/Atoms.cpp
index f4777d2a6..80afd2709 100644
--- a/src/core/Atoms.cpp
+++ b/src/core/Atoms.cpp
@@ -339,6 +339,11 @@ void Atoms::setAtomsNlocal(int n){
   gatindex.resize(n);
   if(dd){
     dd.g2l.resize(natoms,-1);
+// Since these vectors are sent with MPI by using e.g.
+// &dd.positionsToBeSent[0]
+// we make sure they are non-zero-sized so as to
+// avoid errors when doing boundary check
+    if(n==0) n++;
     dd.positionsToBeSent.resize(n*5,0.0);
     dd.positionsToBeReceived.resize(natoms*5,0.0);
     dd.indexToBeSent.resize(n,0);
-- 
GitLab