0

I think I have isolated crash which happens only on cygwin platform. Tried to run with valgrind on linux — no effect, it reports no memory errors. I have function to remove zero monomes from Polynomes

typedef map<multiset<int>, double> Polynome;

void removeZeroes(Polynome&p){
    for(auto it=p.cbegin();it!=p.cend();){
        if(p[it->first]==0.) {
            p.erase(it++);
        } else ++it;
    }
}

void calcGDerivatives(Reduced &r) {
    auto vars = getAllVars(r);
    cout<<"calculating derivatives"<<endl;
    iterate(vars, [&r](multiset<int>k1)->void {
        if (r.grandDerivatives.count(k1)) return;
        Polynome der = r.grandDerivatives[k1];
        for (auto &kv : r.grandPoly) {
            Monome monDer = monomeDeriv(kv.first, k1);
                    multiset<int> p = kv.first;
            if (monDer.first == 0) continue;
                    monDer.first *= kv.second;
                    add(der, monDer);
            }
        removeZeroes(der);
        r.grandDerivatives[k1]=der; //since der is a copy
    });
}

If I replace Polynome der to reference &der and remove r.gr..[k1]=der, then I get a crash. Is it unsafe to modify std::map's value? How can I find a place were problem happens? Thanx!

Stepan Yakovenko
  • 8,670
  • 28
  • 113
  • 206
  • Can you clarify exactly what change causes it to crash? I'm unclear what changes you are talking about in the last sentence. Offhand, your `removeZeroes` function *seems* ok so the problem is probably somewhere else. – Mark B Aug 16 '16 at 02:05
  • What is the return type of `r.grandDerivatives[k1]`? – NathanOliver Aug 16 '16 at 02:55
  • You want to use `if (it->second == 0)`, and not perform another map lookup again. – Kerrek SB Aug 18 '16 at 09:24

1 Answers1

0

I've finally found true cause of the problem. One of my functions looked like this:

stl::vector<...> f(){
   // do something
   // forgot return
}
f();

This immediately gives a crash on cygwin.

Stepan Yakovenko
  • 8,670
  • 28
  • 113
  • 206