0

UPDATE: I was misled by the latest error logs from the debugger. I had to manually disable part by part of code in order to find the error making line.


Could you kindly give me an advice which part of the following code causes (sometimes) heap corruption?

I use Qt on Windows and this sort of a problem is not trivial for me, since there is no Valgrind for Windows.

I have the numerical values in some text files. They are 3-4 digit integers (max 250 of them in one file) separated by white characters. Under 'debug' mode this worked flawless up to some point - when I used 12 text files. I enlarged my database with some additional bigger text files and now it crashes more often. Under 'release' mode the application exits with code -1073741819 most of the times.

Maybe this approach is not appropriate one at all? If so, what are the alternatives?

filesTable[0].open(some_directory);
...

//other files...
...
for(int i=0;i<number_of_files;i++)
{
    vector<string> data_vector;
    string number;
    files[i] >> number;
    while(files[i])
    {
        if (number.size() > 0)
            data_vector.push_back(number);
        files[i] >> number;
    }
    files[i].close();
    int size = data_vector.size();
    int point[size];
    for(int j=0; j<size;j++)
        point[j]=atof(data_vector[j].c_str());
    data_vector.clear();
}
tshepang
  • 12,111
  • 21
  • 91
  • 136
user1432671
  • 71
  • 1
  • 7
  • uhmmm... [valgrind on windows](http://stackoverflow.com/a/6580332/1810087) – user1810087 Dec 12 '13 at 01:55
  • Why aren't you using `vector` here? `int point[size];` Also, why are you using `atof` when you're storing the result in an `int`? – Joe Z Dec 12 '13 at 01:59
  • 2
    Are you sure this is the cause of the heap problem? Often the corruption occurs in one area of code but only manifests somewhere else. – Keith Dec 12 '13 at 02:06
  • Also the declaration of `int point [size];` does not look legal to me; don't array sizes have to be constant? – Keith Dec 12 '13 at 02:07
  • Yes, you are very watchful. This "int point[size]" is a fake. In fact I use a structure one parameter of which is a point coordinate. I tried to simplify the code for you, but without a great success. So you say that this part of the code is not likely causing heap problem? I will try to disable other parts of the code. – user1432671 Dec 12 '13 at 02:10
  • 1
    If you want a real answer best to post the real code. A short complete example works best. – Retired Ninja Dec 12 '13 at 02:16
  • itwasntpete: Been there; I was looking sth I could merge into Qt framework, I know there are tools for Visual Studio. Retired Ninja: you would not like to dive into entire code, but I should have simplify and CHECK whether the error occurs in such a snipped; Keith: Yes, the error is somewhere else -> I was focused on the vector, because some of the latest error logs from debugger indicated connection with vectors... Problem is not solved, but the topic is solved. Thanks for all of you. – user1432671 Dec 12 '13 at 02:29

0 Answers0