From cf00346db482df36b5abeee0aa899e50c4aa33d1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer <akohlmey@gmail.com> Date: Thu, 10 Jan 2019 16:52:40 -0500 Subject: [PATCH] detect when something tries to delete a callback that was never added --- src/atom.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index 315097261b..9958fefc88 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -2044,9 +2044,7 @@ void Atom::delete_callback(const char *id, int flag) { if (id == NULL) return; - int ifix; - for (ifix = 0; ifix < modify->nfix; ifix++) - if (strcmp(id,modify->fix[ifix]->id) == 0) break; + int ifix = modify->find_fix(id); // compact the list of callbacks @@ -2054,6 +2052,8 @@ void Atom::delete_callback(const char *id, int flag) int match; for (match = 0; match < nextra_grow; match++) if (extra_grow[match] == ifix) break; + if ((nextra_grow == 0) || (match == nextra_grow)) + error->all(FLERR,"Trying to delete non-existent Atom::grow() callback"); for (int i = match; i < nextra_grow-1; i++) extra_grow[i] = extra_grow[i+1]; nextra_grow--; @@ -2062,6 +2062,8 @@ void Atom::delete_callback(const char *id, int flag) int match; for (match = 0; match < nextra_restart; match++) if (extra_restart[match] == ifix) break; + if ((nextra_restart == 0) || (match == nextra_restart)) + error->all(FLERR,"Trying to delete non-existent Atom::restart() callback"); for (int i = match; i < nextra_restart-1; i++) extra_restart[i] = extra_restart[i+1]; nextra_restart--; @@ -2070,6 +2072,8 @@ void Atom::delete_callback(const char *id, int flag) int match; for (match = 0; match < nextra_border; match++) if (extra_border[match] == ifix) break; + if ((nextra_border == 0) || (match == nextra_border)) + error->all(FLERR,"Trying to delete non-existent Atom::border() callback"); for (int i = match; i < nextra_border-1; i++) extra_border[i] = extra_border[i+1]; nextra_border--; -- GitLab