When I run a program with the valgreend I get the following:
==6153== Invalid read of size 4
==6153== at 0x401620: estado::n_transiciones() (estadoNFA.cpp:31)
==6153== by 0x401C82: nfa::mostrar(std::ostream&) (NFA.cpp:96)
==6153== by 0x402ADB: main (main_nfa.cpp:49)
==6153== Address 0x38 is not stack'd, malloc'd or (recently) free'd
==6153==
==6153==
==6153== Process terminating with default action of signal 11 (SIGSEGV)
==6153== Access not within mapped region at address 0x38
==6153== at 0x401620: estado::n_transiciones() (estadoNFA.cpp:31)
==6153== by 0x401C82: nfa::mostrar(std::ostream&) (NFA.cpp:96)
==6153== by 0x402ADB: main (main_nfa.cpp:49)
==6153== If you believe this happened as a result of a stack
==6153== overflow in your program's main thread (unlikely but
==6153== possible), you can try to increase the size of the
==6153== main thread stack using the --main-stacksize= flag.
==6153== The main thread stack size used in this run was 8388608.
0 ==6153==
referring to
int estado::n_transiciones(void){
return ntransiciones_;
}
And he also complains about this function
ostream& nfa:: mostrar(ostream& os){
os<<nestados_<<endl;
os<<estadoarranque_<<endl;
map<char,set<int> >::iterator it;
set<int>::iterator ik;
for(int i=0; i<nestados_;i++){
os<<i<<" ";
/*os<<estados_[i].get_aceptacion()<<" ";*/
os<<estados_[i].n_transiciones()<<" ";
for(it=estados_[i].get_transiciones().begin(); it!=estados_[i].get_transiciones().end(); it++){
os<<it->first;
for(ik= (*it).second.begin(); ik!=(*it).second.end() ; ik++){ //vectorestados[i].get_transiciones().second.end() eso no, porque cada posicion del map tiene un second, pero el trans_,lo que te devuelve get_transicion, es un conjunto, no tiene second
os<<(*ik);
}
}
}
return os;
}
the state class NFA hpp
#pragma once
#include<iostream>
#include<map>
#include<vector>
#include<fstream>
#include<string>
#include<set>
#include"estadoNFA.hpp"
using namespace std;
class nfa{
private:
vector<estado> estados_; // como objeto, pues lo que necesito para cada estado, todos los atributos de estadoNFA
int nestados_;
int estadoarranque_;
bool errorapertura_;
public:
nfa();
void leernfa(string nombrefichero);
ostream& mostrar(ostream& os);
void estados_importantes(void);
void estados_muerte(void);
void esdfa(string nombrefichero);
void analizarcadena(void);
};
I do not understand the errors of the valgrind
Thanks