فساد كومة - ناقل push_back
-
30-09-2019 - |
سؤال
يبدو أن لدي كومة تالفة ، لا يمكنني معرفة سبب حدوث ذلك ....
فيما يلي التتبع من فالغريند ..
==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)
الرمز هو مجرد دفع هيكل إلى ناقل. يحتوي الهيكل على عدد قليل من متغيرات السلسلة فيه. واسمحوا لي أن أعرف ما إذا كان المصدر مطلوبًا لمزيد من التصحيح.
بعض المصدر:
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;
تحرير: أنا أدرك أن هذا يعيد "نسخة" .. يتم ذلك اختبار بعض الأشياء ، أنا أدخل نفس الشيء في نسخة من Vector تم تمريرها بالرجوع إليها.
هتافات!
المحلول
في حال getChargeRateDetails
إرجاع بالرجوع إليه ، تحاول استخدام إشارة إلى متغير خارج النطاق بالفعل.
نصائح أخرى
يبدو أن مُنشئ النسخ الخاص بك لا يفعل الشيء الصحيح. من أجل دفع عنصر إلى ناقل ، نسخة من chargeRate
تم إنشاؤه. لأول وهلة،
at 0xDD0725: __gnu_cxx::__atomic_add(int volatile*, int)
chargeRate::chargeRate(chargeRate const&)
يخبرني أن ال chargeRate
يحاول مُنشئ النسخ إضافة شيء إلى متغير غير محدد (أشار إليه int volatile*
حجة __atomic_add
.
ربما أنت __atomic_add
جي لشيء لمتغير عضو غير مهيئ.
StringMatrix *results;
يبدو أنه يهدف إلى الإشارة إلى مجموعة من string
س. من المحتمل أن StringMatrix
لم تتم تهيئته بشكل جيد. وبالتالي ، قد يحتوي الصف الأول على غير محدد string
-مثل قطعة من الذاكرة ، يتم استخدامها لنسخ بناء chargeType
عضو في كائنك الجديد.
ال string
يحتوي الفصل على عداد مرجعي يحتاج إلى زيادة عندما يكون جديد string
يشير إلى نفس البيانات ، لذلك قد يكون هذا منطقيًا.
يمكنك التحقق من ذلك عن طريق (مؤقتًا) تعيين سلسلة فارغة بدلاً من (*results)[FIRST_ROW][CHARGE_TYPE]
.
لست متأكدًا مما يجري في تطبيقك ، ولكن ربما يتعلق الأمر بـ (وليس) باستخدام Back_inserter؟
هناك مثال جيد هنا.