Question

Il me semble avoir un tas corrompu, je ne peux pas comprendre pourquoi ce qui se passe ....

Après la trace de valgrind ..

==12697== Use of uninitialised value of size 4
==12697==    at 0xDD0725: __gnu_cxx::__atomic_add(int volatile*, int) (in /usr/lib/libstdc++.so.6.0.7)
==12697==    by 0x1C3AD9BB: chargeRate::chargeRate(chargeRate const&) (in /root//app/libapp++.so)
==12697==    by 0x1C4C9C22: __gnu_cxx::__mt_alloc_base<chargeRate>::construct(chargeRate*, chargeRate const&) (mt_allocator.h:585)
==12697==    by 0x1C4CAC9F: std::vector<chargeRate, std::allocator<chargeRate> >::_M_insert_aux(__gnu_cxx::__normal_iterator<chargeRate*, std::vector<chargeRate, std::allocator<chargeRate> > >, chargeRate const&) (vector.tcc:284)
==12697==    by 0x1C4CAF9E: std::vector<chargeRate, std::allocator<chargeRate> >::push_back(chargeRate const&) (stl_vector.h:610)
==12697==    by 0x1C4C8A03: WebTranslations::getChargeDetails(std::vector<std::string, std::allocator<std::string> >&, std::vector<chargeRate, std::allocator<chargeRate> >&) (WebTranslations.cpp:427)
==12697==    by 0x1C4C8F83: WebTranslations::getChargeTranslations(std::vector<std::string, std::allocator<std::string> >&, std::vector<std::string, std::allocator<std::string> >&) (WebTranslations.cpp:1172)

==12697== 
==12697== Invalid read of size 4
==12697==    at 0xDB468B: std::string::string(std::string const&) (in /usr/lib/libstdc++.so.6.0.7)
==12697==    by 0x1C3AD9E0: chargeRate::chargeRate(chargeRate const&) (in /root//app/libapp++.so)
==12697==    by 0x1C4C9C22: __gnu_cxx::__mt_alloc_base<chargeRate>::construct(chargeRate*, chargeRate const&) (mt_allocator.h:585)
==12697==    by 0x1C4CAC9F: std::vector<chargeRate, std::allocator<chargeRate> >::_M_insert_aux(__gnu_cxx::__normal_iterator<chargeRate*, std::vector<chargeRate, std::allocator<chargeRate> > >, chargeRate const&) (vector.tcc:284)
==12697==    by 0x1C4CAF9E: std::vector<chargeRate, std::allocator<chargeRate> >::push_back(chargeRate const&) (stl_vector.h:610)
==12697==    by 0x1C4C8A03: WebTranslations::getChargeDetails(std::vector<std::string, std::allocator<std::string> >&, std::vector<chargeRate, std::allocator<chargeRate> >&) (WebTranslations.cpp:427)
==12697==    by 0x1C4C8F83: WebTranslations::getChargeTranslations(std::vector<std::string, std::allocator<std::string> >&, std::vector<std::string, std::allocator<std::string> >&) (WebTranslations.cpp:1172)
==12697==    by 0x1C299E48: zif__get_charge_translations (in /usr/lib/php4/.so)
==12697==    by 0x1BCE0916: zend_do_fcall_common_helper (in /usr/lib/httpd/modules/libphp5.so)
==12697==    by 0x1BCF1088: zend_do_fcall_handler (in /usr/lib/httpd/modules/libphp5.so)
==12697==    by 0x1BCDDD92: execute (in /usr/lib/httpd/modules/libphp5.so)
==12697==    by 0x1BCE02A9: zend_do_fcall_common_helper (in /usr/lib/httpd/modules/libphp5.so)
==12697==  Address 0xFFFFFFFC is not stack'd, malloc'd or (recently) free'd
==12697== 
==12697== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==12697==  GPF (Pointer out of bounds?)
==12697==    at 0xDB468B: std::string::string(std::string const&) (in /usr/lib/libstdc++.so.6.0.7)
==12697==    by 0x1C3AD9E0: chargeRate::chargeRate(chargeRate const&) (in /root//app/libapp++.so)
==12697==    by 0x1C4C9C22: __gnu_cxx::__mt_alloc_base<chargeRate>::construct(chargeRate*, chargeRate const&) (mt_allocator.h:585)
==12697==    by 0x1C4CAC9F: std::vector<chargeRate, std::allocator<chargeRate> >::_M_insert_aux(__gnu_cxx::__normal_iterator<chargeRate*, std::vector<chargeRate, std::allocator<chargeRate> > >, chargeRate const&) (vector.tcc:284)
==12697==    by 0x1C4CAF9E: std::vector<chargeRate, std::allocator<chargeRate> >::push_back(chargeRate const&) (stl_vector.h:610)
==12697==    by 0x1C4C8A03: WebTranslations::getChargeDetails(std::vector<std::string, std::allocator<std::string> >&, std::vector<chargeRate, std::allocator<chargeRate> >&) (WebTranslations.cpp:427)
==12697==    by 0x1C4C8F83: WebTranslations::getChargeTranslations(std::vector<std::string, std::allocator<std::string> >&, std::vector<std::string, std::allocator<std::string> >&) (WebTranslations.cpp:1172)

Le code est tout simplement pousser une structure dans un vecteur. La structure a quelques variables de chaîne en elle. S'il vous plaît laissez-moi savoir si la source est nécessaire pour le débogage plus.

Certains source:

typedef struct{
  string chargeType; // The name of the charge type, eg "Date Units"
  string unitSize;
  string rate;
  bool perConnection;
  string cap;
  bool useMaxDailyCharge;
  string maxDailyCharge;
  string identifier;
} chargeRate;

getChargeDetails:

vector<chargeRate> my_vector;
my_vector.push_back(this->getChargeRateDetails(chargeStructureNames[i]));

getChargeRateDetails:

where : vector<vector<string> > StringMatrix
StringMatrix *results; //used to retrive results from database.
chargeRate chargeInformation;
...
//populate results, check them
..
chargeInformation.chargeType = (*results)[FIRST_ROW][CHARGE_TYPE];
return chargeInformation;

Modifier. Je suis conscient que ce retour est une « copie » .. c'est test effectué quelques petites choses, je suis même en insérez une copie du vecteur passé par référence

Vive!

Était-ce utile?

La solution

Dans le cas retourne getChargeRateDetails par référence que vous essayez d'utiliser une référence à une variable qui est déjà hors de portée.

Autres conseils

Il semble que votre constructeur de copie ne fait pas la bonne chose. Afin de pousser un élément sur un vecteur, une copie de votre chargeRate est créé. A première vue,

at 0xDD0725: __gnu_cxx::__atomic_add(int volatile*, int)
chargeRate::chargeRate(chargeRate const&)

me dit que le constructeur de copie chargeRate tente d'ajouter quelque chose à une variable non initialisée (pointée par l'argument int volatile* de __atomic_add.

Probablement, vous __atomic_adding quelque chose à une variable membre non initialisée.

StringMatrix *results;

Semble destiné à se référer à un tableau de strings. Il y a des chances que le StringMatrix n'est pas initialisé bien. Par conséquent, la première ligne peut contenir un string en forme de pièce de mémoire non initialisée, qui est utilisé pour copier l'élément de construction chargeType de votre nouvel objet.

La classe string contient un compteur de référence qui doit être augmentée si de nouveaux points de string aux mêmes données, donc cela peut avoir un sens.

Vous pouvez le vérifier en (temporairement) par exemple attribution une chaîne vide au lieu de (*results)[FIRST_ROW][CHARGE_TYPE].

Je ne sais pas ce qui se passe dans votre application, mais peut-être qu'il a à faire avec (pas) en utilisant back_inserter?

il est un bon exemple .

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top