Thread: Static memory being overwritten?

  1. #1
    Registered User
    Join Date
    Dec 2005

    Static memory being overwritten?

    --EDIT-- realized it had to do with my char[] size. thanks.

    I am trying to create a PAKer and having issues with my variables suddenly changing out of no where. As soon as i call strcpy in the cody below the packHeader suddenly gets filled up with the name of the file being strcpy'ed and very large number for its data.

    im clueless as to what is going on with my data...

    // Function to pack a single file into an opened pak.
    // Input:   file - filepath of file to pack
    bool PAKUtility::Pack( const char *file )
          , std::ios_base::in | std::ios_base::binary);
    		return false;
    	const int READ_SIZE = 1024;
    	char data[READ_SIZE];
    	// read existing main header
    	m_PakFile.seekg(0, std::ios_base::beg);
    	m_PakFile.seekp(0, std::ios_base::beg);
    	PAKHEADER packHeader;*)&packHeader, sizeof(PAKHEADER));
    	// build & write new header for new file
    	m_newFile.seekg(0, std::ios_base::end);
    	strcpy(, file);
    	fh.fileOffset = packHeader.dirOffset;
    	fh.fileLength = m_newFile.tellg();
    	m_newFile.seekg(0, std::ios_base::beg);
    	m_PakFile.seekg(packHeader.dirOffset, std::ios_base::beg);
    	FILEHEADER* fHeaders = NULL;
    	int numHeaders = (packHeader.dirSize >> 6);
    	if(numHeaders > 0)
    		fHeaders = new FILEHEADER[numHeaders];
    		for(int i = 0; i < numHeaders; i++)*)&fHeaders[i], sizeof(FILEHEADER));
    	// append the new file in chunks
    	m_newFile.seekg(0, std::ios_base::beg);
    	m_PakFile.seekp(packHeader.dirOffset, std::ios_base::beg);
    	while (m_newFile.good())
    	{, READ_SIZE);
    		m_PakFile.write(data, m_newFile.gcount());
    	if(numHeaders > 0)
    		for(int i = 0; i < numHeaders; i++)
    			m_PakFile.write((char*)&fHeaders[i], sizeof(FILEHEADER));
    	m_PakFile.write((char*)&fh, sizeof(FILEHEADER));
    	// Update header
    	packHeader.dirOffset += fh.fileLength;
    	packHeader.dirSize += 64;
    	m_PakFile.seekp(0, std::ios_base::beg);
    	m_PakFile.write((char*)&packHeader, sizeof(PAKHEADER));
    	CListBox* pList = (CListBox*)theApp.GetMainWnd()->GetDlgItem(IDC_LIST2);
    	int counter = pList->GetCount();
    	for(int i = counter - 1; i > 0; i--)
    	for(int i = 0; i < numHeaders; i++)
    	delete [] fHeaders;
    	return true;
    Last edited by JeremyCAFE; 06-17-2006 at 05:36 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tools for finding memory leaks
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2009, 11:41 AM
  2. uploading file to http server via multipart form data
    By Dynamo in forum C++ Programming
    Replies: 1
    Last Post: 09-03-2008, 04:36 AM
  3. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  4. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM