CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Odd program flow occuring

    I have an MFC DLL (old working Visual C++ 6.0 code) that is part of a much larger project (all converted from Visual Studio 6 to .NET 2005). I'm having trouble at one point (at least that I've noticed). The program seems to be flowing to sections in code that make no sense.

    For example, it's in a large if/then/else block and within that is another if statement. It will test the inside if statement(shouldn't take the if block) then jump down to the big else block below the larger if statement its in. Then it jumps back to the end of that larger if block, then back to statement in else block again, then back up to the inside of the inside if statement it shouldn't have taken in the first place.

    I neglect to put specific code, because I don't think code is the problem. Here is an example of the section of monitoring do this.
    Code:
    1  if (condition 1)
    2  {
    3    if (inside condition)
    4    {
    5       inside statement
    6    }
    7  }
    8   else if (condition 2)
    9   {
    10    statement 1
    11 }
    If this represents the description above, then the flow goes like this:
    1
    3 (should NOT take block inside this if e.g. 5)
    10
    7
    10
    5 (inside block it should never have taken in first place)


    OK....my first thought was some sort of stack corruption, but when I view disassembly during debug, it appears to have valid assembly code making these jumps happen.

    So I'm guessing it may be some kind of project setting. Can you think of any project setting that could affect compilation in this way? Thanks for any help/ideas.

    P.S. I can post code if necessary, but I didn't think it was probably relevant and would only complicate the issue.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Odd program flow occuring

    The reason will probably be obvious if you post the real code.

  3. #3
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Re: Odd program flow occuring

    Quote Originally Posted by GCDEF View Post
    The reason will probably be obvious if you post the real code.
    OK, you asked for it, however, I still don't think its a code problem as this is working code in Visual Studio 6. It's not my code, just mine to maintain/update at the moment....so refrain from "bad code" comments unless you see something truly wrong.


    Here is the function where the problem described above is happening. See wonky lines in purple comments.

    Code:
    BOOL CTestCatalog::IsValidSequence(CSequence *pSequence, BOOL bUseSource)
    {
       ASSERT_VALID(pSequence);
       ASSERT_KINDOF(CSequence, pSequence);
    
       if (pSequence)
       {
          // verify if sequence with the same name is already loaded
          if (GetSequence(pSequence->GetName()) != NULL)
          {
             return FALSE;
          }
    
          // if not verifying against source and made it until this point - we are done
          if (!bUseSource)
          {
             return TRUE;
          }
    
          // verify if name and source are present
          if (pSequence->GetName().IsEmpty() || pSequence->GetSource().IsEmpty())
          {
             return FALSE;
          }
    
          if (stTest == pSequence->GetType())
          {
             // if the source for this sequence is not the currently loaded test properties
             // file - return FALSE;
             CString strSourceName = pSequence->GetSource();
             if (0 != GetFileName().CompareNoCase(pSequence->GetSource()))
             {
                //here the full TPF path is checked against
                //what is saved in the sequence file
                //if it fails, then do a strfind with the 
                //backslash appended to the source name
                //to guarantee the full name is found,
                //not just some substr of a name.
    
                //example:
                //getfilename = c:\rts\delta\egpws\egpws tpf.txt
                //psequence->GetSource = egpws tpf.txt
                //strfind \egpws tpf.txt
                //guarantees full tpf name.
    
    
                CString strSequenceSource = "\\";
                strSequenceSource += pSequence->GetSource();
    			CString strTemp = GetFileName();
    			int iIdx = strTemp.Find(strSequenceSource);
                //if(GetFileName().Find(strSequenceSource) < 0)
    // ***** [1]THIS IS WHERE THE LOGIC GOES WONKY
    			if (iIdx < 0)
                {
                   return FALSE; // ***** [4] idx == 22, should not come in here
                }
             }
    
    
             if (GetTestCount() != pSequence->GetSourceItemCount())
             {
                return FALSE;
             }
    
             volatile int j = 0;
    		 volatile int i = 0;
             for (i = 0; (i < GetTestCount()) && (j < pSequence->GetItemCount()); i++)
             {
                if (GetTestAttribute(GetTestId(i), _T("TestGroup")).IsEmpty())
                {
                   // this is a procedure - ignore it, continue
                   continue;
                }
    
                if (GetTestId(i) == pSequence->GetItem(j)->GetTestId())
                {
                   j++;
                }
                else
                {
                   // if mismatch of testids - it is not the original sequence from
                   // which this user sequence was generated
                   return FALSE;
                }
             }
    
             if ((i != GetTestCount()) && (j != pSequence->GetItemCount()))
             {
                return FALSE;
             }
          } // ***** [3]
          else if (stUser == pSequence->GetType())
          {
    // ***** [2] THIS IS THE LINE THAT COMES AFTER [1] again after [3]
             CSequence* pSrcSequence = GetSequenceCatalog()->GetSequence(pSequence->GetSource());
             if (pSrcSequence == NULL)
             {
                return FALSE;
             }
    
             if (pSrcSequence->GetItemCount() != pSequence->GetSourceItemCount())
             {
                return FALSE;
             }
    
             int j = 0;
             for (int i = 0; (i < pSrcSequence->GetItemCount()) && (j < pSequence->GetItemCount()); i++)
             {
                if (!pSrcSequence->GetItem(i)->IsSelected())
                {
                   // if item is not selected - skip the following statements
                   continue;
                }
    
                if (pSrcSequence->GetItem(i)->GetTestId() == pSequence->GetItem(j)->GetTestId())
                {
                   // if source item is selected and id is the same as current item
                   j++;
                }
                else
                {
                   // source has been modified - user sequence is invalid
                   return FALSE;
                }
             }
    
             if (j != pSequence->GetItemCount())
             {
                return FALSE;
             }
          }
          else
          {
             return FALSE;
          }
       }
    
       return TRUE;
    }
    Flow goes something like 1-2-3-2-4.

  4. #4
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Re: Odd program flow occuring

    BTW, in case you are wondering, optimization is disabled. *FYI*

  5. #5
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Odd program flow occuring

    Quote Originally Posted by KingTermite View Post
    BTW, in case you are wondering, optimization is disabled. *FYI*
    Yeah, I was wondering about that.
    BTW, how sure are you that it is in fact disabled?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  6. #6
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Re: Odd program flow occuring

    Quote Originally Posted by VladimirF View Post
    Yeah, I was wondering about that.
    BTW, how sure are you that it is in fact disabled?
    I "believe" it is.......here are CPP and Linker Optimizations (didn't change anything in linker except win98 optimization as it didn't look to do much).





    Am I missing some optimization that could be playing a role?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured