Segfault when hsolve.target is set and a PulseGen is connected
Created by: subhacom
The python script tests/python/hsolve/three_compartments.py
has following snippet:
def setup_stim():
pulseGen = moose.PulseGen('/data/pulse')
pulseGen.level[0] = 1e-10
pulseGen.width[0] = 0.25
pulseGen.delay[0] = 0.0
pulseGen.delay[1] = 0.50
pulseGen.connect('output', cable[0], 'injectMsg')
def setupHSolve():
global cable
hsolve = moose.HSolve('/hsolve')
moose.useClock(1, '/hsolve', 'process')
hsolve.dt = 1e-6
hsolve.target = '/cable'
This scripts fails with seg-fault. (If I don't connect PulseGen or don't set hsolve.target then the script runs fine.)
I was able to locate the source of seg-fault to following snnippet in Clock::handleReinit
function. The seg-fault only become visible here if following diff is applied.
diff --git a/scheduling/Clock.cpp b/scheduling/Clock.cpp
index e9ae057..e0e8575 100644
--- a/scheduling/Clock.cpp
+++ b/scheduling/Clock.cpp
@@ -50,6 +50,7 @@
#include "header.h"
#include "Clock.h"
+#include "../external/debug/testing_macros.hpp"
const unsigned int Clock::numTicks = 10;
@@ -560,7 +561,9 @@ void Clock::handleReinit( const Eref& e )
for ( vector< unsigned int>::iterator j =
activeTicks_.begin(); j != activeTicks_.end(); ++j ) {
info_.dt = *j * dt_;
- reinitVec()[*k++]->send( e, &info_ );
+ vector< SrcFinfo1< ProcPtr >* > vec = reinitVec();
+ EXPECT_LT( *k++, vec.size(), "Illegal access in vector");
+ vec[*k++]->send( e, &info_ );
}
info_.dt = dt_;
doingReinit_ = false;
This causes following seg-fault in testCloc()
in Clock::handleReinit
function with following error.
..........................................
[EXPECT_FAILURE] In function: void Clock::handleReinit(const Eref &) file: scheduling/Clock.cpp:565
+ Expected less than 10, received 1701602660
+ Illegal access in vector
+
In short, in original code i.e. reinitVec()[*k++]->send( e, &info_ );
, accessing an element at illegal location is allowed, but once it is changed: get the vector first and then access its element and added a macro to test, it fails.
I am not sure if this is a bug but I found this to be unexpected.
NOTE: Seg fault is reproducible with g++-4.8. Similar message is printed but the line in console + Expected less than 10, received 1701602660
is screwed up and garbage value is printed as 0
or some very small no which does not make since it is less than 10 in any case.
This version of code is not pushed to svn repo since few macros have been added to original code at various places.
Reported by: dilawar