Fix UB when generating local indices for constraints
[alexxy/gromacs.git] / src / gromacs / mdlib / groupcoord.cpp
index bd8711ce77f5e85d3d0975913935adcc8a019e36..adbf364c896113549b796f232d704f99989682ae 100644 (file)
@@ -3,7 +3,8 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2012,2014,2015,2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015,2017,2018 by the GROMACS development team.
+ * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -58,9 +59,10 @@ void dd_make_local_group_indices(const gmx_ga2la_t* ga2la,
                                  int* nr_loc,     /* OUT: Number of group atoms found locally */
                                  int* anrs_loc[], /* OUT: Local atom numbers of the group  */
                                  int* nalloc_loc, /* IN+OUT: Allocation size of anrs_loc */
-                                 int  coll_ind[]) /* OUT (opt): Where is this position found in the collective array? */
+                                 int coll_ind[]) /* OUT (opt): Where is this position found in the collective array? */
 {
     GMX_ASSERT(ga2la, "We need a valid ga2la object");
+    GMX_RELEASE_ASSERT(anrs != *anrs_loc, "Can not update indices in-place");
 
     /* Loop over all the atom indices of the group to check
      * which ones are on the local node */