Thread: Crash after crash!

  1. #1
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802

    Crash after crash!

    Does anyone see the problem with the following code? I've ran it through the debugger, but I'm unable to isolate it completely.


    It's somewhere within this loop.. it will run three times, but after the third.. it crashes (assertion error).

    Code:
    for (int i = 1; i < (tagOffset[1] - tagOffset[0] - 1); i++)
    {
    	CString gotAtOffset = entireLine.GetAt(i + tagOffset[0]);
    	subString = subString + gotAtOffset;
    
    	if (gotAtOffset == '=' && !inAttrib)
    	{
    		inAttrib = 1;
    	} else if (gotAtOffset == '"' && inAttrib && !foundFirstQuote) {
    		isWhiteSpaceAttrib = 0;
    		foundFirstQuote = 1;
    	} else if (gotAtOffset == '"' && inAttrib && foundFirstQuote) {
    		inAttrib = 0;
    		isWhiteSpaceAttrib = 0;
    		foundFirstQuote = 0;
    		okToModNextChar = 1;
    	} else if (gotAtOffset == ' ' && inAttrib && isWhiteSpaceAttrib) {
    		inAttrib = 0;
    		isWhiteSpaceAttrib = 0;
    		okToModNextChar = 1;
    	} else if (okToModNextChar && !inAttrib) {
    		if (m_bCase)
    		{
    			int iLeng = subString.GetLength();
    			
    			gotAtOffset.MakeUpper();
    			subString.SetAt(iLeng-1, gotAtOffset.GetAt(0));
    		} else {
    			int iLeng = subString.GetLength();
    			
    			gotAtOffset.MakeLower();
    			subString.SetAt(iLeng-1, gotAtOffset.GetAt(0));
    		}
    	}
    }
    That being part of the much larger code:


    Code:
    void CHTMLConvertDlg::OnConvert() 
    {
    	UpdateData(TRUE);
    	m_sStatus = "Converting";
    	CFile fileHTML;
    	fileHTML.Open(m_sFileName, CFile::modeReadWrite | CFile::shareDenyWrite, NULL);
    	BeginWaitCursor();
    
    	while (m_dBytesRead < fileHTML.GetLength())
    	{
    		OnPaint();
    		CString entireLine;
    		//Force tempLine to dissappear;
    		{	
    			
    			char tempLine[4096];
    			fileHTML.Read(tempLine, 2048);
    			m_iLinesRead++;
    			entireLine = tempLine;
    			//AfxMessageBox("4");
    
    			//Ensure the line doesn't consist of a whitespace character;
    			m_dBytesRead =+ entireLine.GetLength();
    			UpdateData(FALSE);
    			entireLine.TrimRight();
    			
    		}
    
    		if (!entireLine.IsEmpty())
    		{
    			//AfxMessageBox("5");
    			//'<' and '>' tag offsets.
    			signed int tagOffset[2] = { 0, 0 };
    			signed int tempOffset[2] = { 0, 0 };
    
    			//The following variables ensure no tag attributes are modified;
    			bool inAttrib = 0; //Are we inside a tags attribute?
    			bool isWhiteSpaceAttrib = 0; //Is the attribute surrounded by quotes, or is it delimited by a whitespace character?
    			bool foundFirstQuote = 0; //Did we find the first quote character?
    			bool okToModNextChar = 0; //OK to change the case of the next character?
    
    //			AfxMessageBox("6");
    			for 
    				
    				(
    					tempOffset[0] = entireLine.Find('<', tagOffset[0]), //First instance of '<';
    					tagOffset[0] = tempOffset[0];
    					tagOffset[0] != -1; //Loop until there is no more '<' tags;
    					tagOffset[0] = tagOffset[1] //Set the offset of '<' to '>' to force searching beyond the current tag;
    				)
    			{
    				tempOffset[1] = entireLine.Find('>', tagOffset[1]);
    				tagOffset[1] = tempOffset[1];
    
    				CString subString;
    				//AfxMessageBox("7");
    				for (int i = 1; i < (tagOffset[1] - tagOffset[0] - 1); i++)
    				{
    					CString gotAtOffset = entireLine.GetAt(i + tagOffset[0]);
    					subString = subString + gotAtOffset;
    
    					if (gotAtOffset == '=' && !inAttrib)
    					{
    						inAttrib = 1;
    					} else if (gotAtOffset == '"' && inAttrib && !foundFirstQuote) {
    						isWhiteSpaceAttrib = 0;
    						foundFirstQuote = 1;
    					} else if (gotAtOffset == '"' && inAttrib && foundFirstQuote) {
    						inAttrib = 0;
    						isWhiteSpaceAttrib = 0;
    						foundFirstQuote = 0;
    						okToModNextChar = 1;
    					} else if (gotAtOffset == ' ' && inAttrib && isWhiteSpaceAttrib) {
    						inAttrib = 0;
    						isWhiteSpaceAttrib = 0;
    						okToModNextChar = 1;
    					} else if (okToModNextChar && !inAttrib) {
    						if (m_bCase)
    						{
    							int iLeng = subString.GetLength();
    							
    							gotAtOffset.MakeUpper();
    							subString.SetAt(iLeng-1, gotAtOffset.GetAt(0));
    						} else {
    							int iLeng = subString.GetLength();
    							
    							gotAtOffset.MakeLower();
    							subString.SetAt(iLeng-1, gotAtOffset.GetAt(0));
    						}
    					}
    				}
    
    				for (i = 1; i < (tagOffset[1] - tagOffset[0]); i++)
    				{
    					entireLine.SetAt(i + tagOffset[0], subString.GetAt(i + tagOffset[0]));
    				}
    				tagOffset[1]++;
    			}
    			fileHTML.Write(entireLine, entireLine.GetLength());
    		}
    	}
    	EndWaitCursor();
    	m_sStatus = "Finished!";
    	UpdateData(FALSE);
    
    }
    If anyone needs any more info on the error.. ask me, I'm not too good with the debugger yet so I can't isolate it myself. I've been working for the past hour trying to find this, but it eludes me and I've grown tired.

    Thanks.
    Last edited by Dual-Catfish; 03-30-2002 at 07:59 PM.

  2. #2
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802

    Some more info

    After crashing in debug, the compiler seeks to this line (within the CString class) and points to it with a yellow arrow.


    Code:
    _AFX_INLINE TCHAR CString::GetAt(int nIndex) const
    {
    	ASSERT(nIndex >= 0);
    ->	ASSERT(nIndex < GetData()->nDataLength);
    	return m_pchData[nIndex];
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. Hooking Crash?
    By Elysia in forum Windows Programming
    Replies: 9
    Last Post: 03-15-2008, 01:13 PM
  3. Can not debug a crash
    By hannibar in forum Windows Programming
    Replies: 2
    Last Post: 06-30-2007, 10:02 AM
  4. Dynamic array sizing causes crash
    By Mithoric in forum C++ Programming
    Replies: 3
    Last Post: 12-30-2003, 07:46 AM
  5. FYI: asctime(gmtime(&mytime)) = crash!
    By anonytmouse in forum C Programming
    Replies: 2
    Last Post: 09-29-2003, 02:24 AM