My program mycpp.c throws memory error,i think this error has been raised due to overwrite the object pointer but i couldn't trace out
root cause of the error.I felt that the line "ref3[1]= ref3[0] +reference;" is causing an issue and i commented it so .but it didnt helped me.could you please help me to resolve the error.
mycpp.c
(gdb) bt
#4 0x00000031690758db in free () from /lib64/libc.so.6
#5 0x0000000000402fda in String::~String (this=0x7fffffffd2f0, __in_chrg=<value optimized out>) at String.c:55
#6 0x000000000040d58c in mycpp::filldata (this=0x61f0e0, pStData=0x7fffffffdd50) at mycpp.c:1955
#7 0x000000000041159d in mycpp::base (this=0x61f0e0, pStData=0x7fffffffdd50, account_id=0x6418e0 "0300130",
page_balance=0x7fffffffdf38, items_on_page=0x7fffffffdf34, txn_per_acc=0x7fffffffdf30, total_cash_bal=0x7fffffffdf28, total_cv_bal=0x7fffffffdf20)
at mycpp.c:1328
#8 0x0000000000414e77 in mycpp::Proc (this=0x61f0e0) at mycpp.c:899
#9 0x000000000041704e in mycpp::Run (this=0x61f060) at mycpp.c:97
#10 0x0000000000417146 in main (argc=3, argv=0x7fffffffe1f8) at mycpp.c:2264
Thanks for looking into this. Seeking your valuable solution
Thank you for looking into this
1.what if ch is null?
I had this question in my mind when the assignment operator overloading function is invoked.i got the error so i commented the piece of code( // ref3[1]= ref3[0] +reference; )
could you please help how to handle this condition?
2.Do you really need the cast?
Its the fix for another issue
3.uninitialsed _text, len 1 whereas the constructor has len 2? and
But seriously, what do you think this does?
_text will always be initialized.Because the object pointer of the class holds a value before it gets erased and then new value will be assigned
I feel that the two lines are not required .If would remove this code then the
1 2 3 4 5 6 7
1948 strcat(ref3[0],reference);
1949 // ref3[1]= ref3[0] +reference;
1951 ref3[0].replace_char('-','.');
1952 // Clean and hold the output value
1953 temp_Buffer->erase();
1954 *temp_Buffer = "";
1955 cout<<"S2:\t"<<s2<<endl;
4.uninitialsed _tex. length is not recorded anywhere
i couldnt understand the question
You've questioned all the points except the one that's causing the crash. The answer to point 5 is it corrupts the heap, causing a crash when you try to use it later on.
1. You have to decide what passing NULL means. It could mean clear(), you have to decide and implement it. You can't ignore it.
2. You shouldn't have a cast there. All your C string interfaces should be const char*, but you keep passing char*. It's an important point. Oh, and _text should remain char*.
3 and 4. _text is always pointing to memory allocated off the heap, but you never really know how much data is allocated because you don't store it. So you don't know how much data can be copied in.
1.But seriously, what do you think this does?
I have answered this question in point#3
I feel that the two lines are not required .If i would remove the line then the code will be modified into ref3[0].replace_char('-','.');
[code]
1948 strcat(ref3[0],reference);
1949 // ref3[1]= ref3[0] +reference;
1951 ref3[0].replace_char('-','.');
1952 // Clean and hold the output value
1953 temp_Buffer->erase();
1954 *temp_Buffer = "";