Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
string passed by value deleted before usage?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="nusch, post: 4094021"] I couldn't seperate this bug because of its nature, if it would be syntax problem or logic of application , I could generate one small source, but the place where exactly is the error is what I'm actually asking for so pasting only part of code could hide the memory coruuption. The error about 'invalid read' from valgrind is the only error shown by this tool. So there are not any 'invalid write' and any "new" which could overwrite segfaulting memory region. So what else could cause coruption? Here are repo cpp: [URL]http://pastebin.com/GsBusbXx[/URL] and most important methods: File* Repo::get_file(string file_name, unsigned int rev_id) { File* f = new File(file_name); if(rev_id>revisions.size()) { cout << "Invalid revision number" << endl; return f; } unsigned int rev_i = 0; list<Revision*>::iterator iter = revisions.begin(); while(++rev_i<=rev_id) { cout << "DEBUG: " << file_name << endl; Patch* tmp = (*iter)->patch_per_file_map[file_name]; tmp->lines.begin(); Patch* p1 = (*iter++)->patch_per_file_map[file_name]; f->patch(*p1); } return f; } void Repo::commit(string desc) { ifstream file("repo.vcs"); if(!file.is_open()) { cout << "No repository in current directory found, creating new.." << endl; init_new(); return; } file.close(); load(); int* eee = new int[2]; delete[] eee; Revision* new_rev = new Revision(revisions.size()+1); map<string, Patch*>::iterator iter; list<string>::iterator fnames_iter; int* fff = new int[2]; delete[] fff; iter = revisions.back()->patch_per_file_map.begin(); int* ggg = new int[2]; delete[] ggg; cout << iter->first << endl; int* hhh = new int[2]; delete[] hhh; while(iter!=revisions.back()->patch_per_file_map.end()) versioned_files.push_back(iter++->first); check_new_files(); fnames_iter = versioned_files.begin(); while(fnames_iter!=versioned_files.end()) { string fname = *fnames_iter; File disk_file(fname); disk_file.read_from_file(fname); cout << fname << endl; cout << revisions.size() << endl; File* latest_repo = get_file(fname, revisions.size()); new_rev->patch_per_file_map[fname] = latest_repo- ++fnames_iter; } ofstream outfile ("repo.vcs", ios::app); outfile << "[[[[[rev" << revisions.size()+1 << "]]]]]\n"; outfile << new_rev->to_str(); outfile << "[[[[[-]]]]]" << endl; outfile.close(); revisions.push_back(new_rev); //delete new_rew; } void Repo::load() { repo_file = new File("repo.vcs"); vector<string>::iterator i = repo_file->lines.begin(); while(i!=repo_file->lines.end()) { cout << *i << endl; unsigned int rev_id; if(!i->find("[[[[[")) { //current line is begining of revisin string tmp = (*i).substr(5,i->length()-10); if(tmp!="-") { tmp = tmp.substr(3); istringstream myStream(tmp); myStream >> rev_id;// endl;//8, i->size()-13); //i- add_revision(rev_id); } else revisions.back()->parse(); //if all lines from current revision was iterated, further processing - dividing revision to files is passed to Revsion class } else { //current line is content of revision revisions.back()->feed(*i); } ++i; } //cout << " //if line = [[[ //while //revisions.push_back(Revision() } [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
string passed by value deleted before usage?
Top