I do the following:
Code:
unsigned char* tmp_data = new unsigned char[this->_level_size*this->_level_size*4 + 1];
tmp_data[this->_level_size*this->_level_size*4] = '\0';
std::ifstream in_file(levelmap.c_str(), std::ios::in | std::ios::binary);
in_file.read((char *)&tmp_data,this->_level_size*this->_level_size*4);
in_file.close();
Yet, it often segfaults. When I run with GDB, it says that the address pointed to by "tmp_data" is "out of bounds." When I run with valgrind, I get similar errors. This code seems like it should be perfectly innocent. What am I doing wrong?