[GiNaC-devel] segmentation fault in substituting.

Chris Dams C.Dams at science.ru.nl
Mon Sep 27 14:04:03 CEST 2004


Dear GiNaCers,

I found that basic::subs_one_level sometimes gives a segementation fault.
This is because the branch that takes care of the no_pattern option, tries
to find *this in the exmap that contains the substitution. This invokes
the construction of a temporary ex from *this. If it turns out that
.eval() wants to change the ex in something else, the this pointer is
going to be deleted, because, presumably, it was allocated with the
dynallocated flag set, by basic::subs. If no substitution is found, it is
tried to return the just deleted this pointer. Not a good idea... I
suggest the change below in the basic::subs_one_level function in
basic.cpp.

***************
*** 603,611 ****
   exmap::const_iterator it;

   if (options & subs_options::no_pattern) {
!     it = m.find(*this);
      if (it != m.end())
         return it->second;
   } else {
      for (it = m.begin(); it != m.end(); ++it) {
         lst repl_lst;
--- 617,627 ----
   exmap::const_iterator it;

   if (options & subs_options::no_pattern) {
!     ex thisex=*this;
!     it = m.find(thisex);
      if (it != m.end())
         return it->second;
+     return thisex;
   } else {
      for (it = m.begin(); it != m.end(); ++it) {
         lst repl_lst;

Best,
Chris




More information about the GiNaC-devel mailing list