Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    There's two behaviors that I have seen so far. One is the corruption issue I caught earlier and the other is your access violation. If not the result of the same defect they are they are both defects caused by poor design/programming practices.
    I no longer wish to be associated with this site.
  2. #17
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2009
    Posts
    6
    Rep Power
    0

    Angry Noted But Bug Still Present Cliff!


    Originally Posted by clifford
    You seem to have missed the point of JD's comment. He was referring to the ridiculous definition of comparison operator macros as an apparent attempt to redefine your own language.

    The really bizarre thing is that having defined them you have used them in some places but not others. In a language where macros for perhaps anything other than literal constants are generally considered a 'bad thing'(tm), those are amongst the most pointless and insidious examples of abuse. The whole semantics of your program can be changed by changing the definitions of those macros, and you might be debugging the code for a long time before you noticed the cause.

    It is just barely acceptable to define such macros if you happen to be using a keyboard without the necessary symbols (if there is such a thing), but I would imagine that anyone doing a significant amount of C code in a region with such a keyboard would just get a US or UK keyboard specifically for that purpose.

    Clifford.
    Hey Cliff, I don't dispute that any strongly, but there are probably only two places where 'my good macros addon style' has been violated...

    Code:
    if (fread(kbmtx[i], sizeof(double), n, kbfile) != n)
    and

    Code:
    if((fwrite(kbmtx[i],sizeof(double),(n+1),kbfile))!=(n+1))quitapp(m,kbmtx,kylst);
    ...fortunately NOT with any disastrous results, because the code there has simply defaulted to standard C coding style of using !=, ==, etc. Pls note that this code assumes a lot of concern about the usage of malloc/realloc/free. Error and omissions may be very apparent elsewhere.

    I however, have made all the suggested corrections, so far deemed important, all with the same damn results - the BUG!

    If I could just major on the majors, why is the code bugging after the 3rd entry only???
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    Originally Posted by deendee
    If I could just major on the majors, why is the code bugging after the 3rd entry only???
    Elementary Watson, elementary...
    I no longer wish to be associated with this site.
  6. #19
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    Send me a personal message and we can exchange email addresses or just drill down into my profile to find my web site and send me an email. There's no point in cluttering up this forum with this until we're ready to post the solution. I have a lot to say about this program that might be instructive to the newbs around here.
    I no longer wish to be associated with this site.
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    Originally Posted by deendee
    Where am I going wrong???
    The obvious answer to that question jumps out in the code metrics. Your main function has a cyclomatic complexity of 52.

    Metrics Details For File 'icky.c'
    --------------------------------------------------------------------------------------------

    Parameter Value
    ========= =====
    Project Directory ...\Projects\Test\app\
    Project Name testApp
    Checkpoint Name Baseline
    File Name icky.c
    Lines 269
    Statements 193
    Percent Branch Statements 26.4
    Percent Lines with Comments 6.7
    Functions 5
    Average Statements per Function 59.2
    Line Number of Most Complex Function 64
    Name of Most Complex Function main()
    Complexity of Most Complex Function 52
    Line Number of Deepest Block 213
    Maximum Block Depth 9+
    Average Block Depth 4.40
    Average Complexity 11.60

    --------------------------------------------------------------------------------------------
    Names of 5 Functions Complexity, Statements, Max Depth, Calls

    deallocate2C() 2, 6, 2, 2
    deallocate2D() 2, 6, 2, 2
    main() 52, 152, 10, 110
    quitapp() 1, 5, 1, 5
    restartapp() 1, 5, 1, 5

    --------------------------------------------------------------------------------------------
    Block Depth Statements

    0 19
    1 33
    2 7
    3 12
    4 16
    5 20
    6 30
    7 32
    8 18
    9+ 6
    --------------------------------------------------------------------------------------------
    I no longer wish to be associated with this site.
  10. #21
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    I think I finally killed your bug. The code still needs some cleanup.

    Code:
    C:\Documents and Settings\Joseph Donahue\My Documents\Visual Studio 2008\Projects\Test\Debug>app -i
    /* Created a new DIM file */
    /* Created a new KY list file */
    /* Created a new KB list file */
    /* Found a valid DIM file showing 0x0 to be the last known dimensions */
    /* Locate and try reading the stored KY list file */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    Q!
    
    Cleaned up.
    Exiting.
    Bye!
    
    C:\Documents and Settings\Joseph Donahue\My Documents\Visual Studio 2008\Projects\Test\Debug>app
    /* Found a valid DIM file showing 0x0 to be the last known dimensions */
    /* Locate and try reading the stored KY list file */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    String1
    Committing to KY list file
    /* Opening the KB binary data file for writing */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    Q!
    
    Cleaned up.
    Exiting.
    Bye!
    
    C:\Documents and Settings\Joseph Donahue\My Documents\Visual Studio 2008\Projects\Test\Debug>app  <
    testInput2.txt
    /* Found a valid DIM file showing 1x1 to be the last known dimensions */
    /* Locate and try reading the stored KY list file */
    /* Resize 'char** kylst' to accommodate the last known rows : 1 */
    /* Locate and try reading the stored KB data file */
    /* Resize 'double **kbmtx' to accommodate the last known dimensions : 1x1 */
    /* Initialize KB with zeros. */
    0
    /* Close the binary file */
    /* Now print KB to the screen. */
    0
    /* Show KB RAM addresses on the screen. */
    3419000
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    Committing to KY list file
    /* Opening the KB binary data file for writing */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    Committing to KY list file
    /* Opening the KB binary data file for writing */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    Committing to KY list file
    /* Opening the KB binary data file for writing */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    Committing to KY list file
    /* Opening the KB binary data file for writing */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    Committing to KY list file
    /* Opening the KB binary data file for writing */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    Committing to KY list file
    /* Opening the KB binary data file for writing */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    
    Cleaned up.
    Exiting.
    Bye!
    
    C:\Documents and Settings\Joseph Donahue\My Documents\Visual Studio 2008\Projects\Test\Debug>app  <
    testInput2.txt
    /* Found a valid DIM file showing 7x7 to be the last known dimensions */
    /* Locate and try reading the stored KY list file */
    /* Resize 'char** kylst' to accommodate the last known rows : 7 */
    /* Locate and try reading the stored KB data file */
    /* Resize 'double **kbmtx' to accommodate the last known dimensions : 7x7 */
    /* Initialize KB with zeros. */
    0	   0	   0	   0	   0	   0	   0
    0	   0	   0	   0	   0	   0	   0
    0	   0	   0	   0	   0	   0	   0
    0	   0	   0	   0	   0	   0	   0
    0	   0	   0	   0	   0	   0	   0
    0	   0	   0	   0	   0	   0	   0
    0	   0	   0	   0	   0	   0	   0
    /* Close the binary file */
    /* Now print KB to the screen. */
    0	   0	   0	   0	   0	   0	   0
    0	   0	   0	   0	   0	   0	   0
    0	   0	   0	   0	   0	   0	   0
    0	   0	   0	   0	   0	   0	   0
    0	   0	   0	   0	   0	   0	   0
    0	   0	   0	   0	   0	   0	   0
    0	   0	   0	   0	   0	   0	   0
    /* Show KB RAM addresses on the screen. */
    3419384 3419392 3419400 3419408 3419416 3419424 3419432
    3419488 3419496 3419504 3419512 3419520 3419528 3419536
    3419592 3419600 3419608 3419616 3419624 3419632 3419640
    3419696 3419704 3419712 3419720 3419728 3419736 3419744
    3419800 3419808 3419816 3419824 3419832 3419840 3419848
    3419904 3419912 3419920 3419928 3419936 3419944 3419952
    3420008 3420016 3420024 3420032 3420040 3420048 3420056
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    Committing to KY list file
    /* Opening the KB binary data file for writing */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    Committing to KY list file
    /* Opening the KB binary data file for writing */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    Committing to KY list file
    /* Opening the KB binary data file for writing */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    Committing to KY list file
    /* Opening the KB binary data file for writing */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    Committing to KY list file
    /* Opening the KB binary data file for writing */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    Committing to KY list file
    /* Opening the KB binary data file for writing */
    Type and Store Another String Or Type Q! and <ENTER> To Quit:
    
    Cleaned up.
    Exiting.
    Bye!

    Comments on this post

    • aitken325i agrees
    I no longer wish to be associated with this site.
  12. #22
  13. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    So I got it down to only a pair of functions that exceed a cyclomatic complexity of 15. Note that it has been shown that functions with complexity exceeding 10 harbor something like 90% of all software defects. Experts are generally in agreement that when the cyclomatic complexity exceeds 10, it's fairly difficult to read and understand what the code does. When it exceeds 15 most coders can't hold all the possible execution paths in their head. By the time you get to 20, you're looking to get fired if you work for me; because you're well beyond the complexity that a code reviewer can grok without spending hours or days in that one function.

    It is very difficult to estimate levels of effort to review, document or make modifications to such code. About the only thing you can tell at a glance is that cohesion will be very low and coupling is likely to be very high. So we have three leading indicators that quality is low. Initial tests indicated several symptoms of what could be the same defect or possibly had multiple causes (varying path coverage sometimes yielded the same symptom). When initial stack traces didn't lead to the root cause I decided the only way to tackle the problem was to actually understand the program well enough to simplify it to the point where the defects would be obvious or simply eliminated in the simplification process. Note that in hind sight, I probably could have found one of the defects by laboriously stepping through the code and rationalizing every single state, but that probably would have taken just as long anyway.

    The first step was to add trace and diagnostic output and that required making changes to the program's parameter handling. I collected some trace runs and confirmed my earlier findings in the debugger. I needed to simplify the code to a point where I could confidently remove whole blocks of functionality to figure out which of the pathways were causing issues and still be sure I had a more or less faithful repro of the remaining code. To achieve that I had to reduce the coupling between certain aspects of the program. The first obvious point of attack was the command line argument handling (nearly trivial changes) followed by the data initialization path ways (tumorous/insidious, initially difficult and only half completed at this point).

    I managed to break it down to max complexity in main() at 22 and readData() at 22. I predict there are still latent defects in this code, but I haven't been able to get it to crash using a dozen different data sets and test scenarios (obviously not exhaustive), all of which lead to crashes in the OP's original code (reasonably conclusive). I am fairly certain the behavior regarding the data files is consistent with the original design, but it's hard to say for sure since the only design artifact I have available is a defective code base with no useful comments what-so-ever.

    Note that I worked open loop initially due to the uncertainties. It took nearly 8 hours of effort spread out over several days to get a handle on and fix the bugs. About half that effort involved addition of debug and trace code that should have been part of the original. Now complexity and coupling is reduced and cohesion increased sufficiently that any good software engineer could estimate what the final form of this code should be. IMO, it needs a minimum of 4 to 6 additional functions to get the peak complexity below 15 and probably closer to 10 additional functions to get it down to a peak cyclomatic complexity less than 10. Based on what I have gleaned from the program behavior; I am fairly confident that problem does not require a solution with functions that exceed a complexity metric of 10 and given that it's a stripped down excision from a larger program that will probably do something useful; it probably warrants the additional effort.

    I will post the code when I get my beer from deendee.

    Here's the current code metrics:

    Code:
    Metrics Details For File 'app.cpp'
    --------------------------------------------------------------------------------------------
    
    Parameter				Value
    =========				=====
    Project Directory			...\Projects\Test\app\
    Project Name				testAppCPP
    Checkpoint Name				Checkpoint8
    File Name				app.cpp
    Lines					548
    Statements				322
    Percent Branch Statements		18.3
    Percent Lines with Comments		6.8
    Classes Defined				0
    Methods Implemented per Class		0.00
    Average Statements per Method		0.0
    Line Number of Most Complex Function	221
    Name of Most Complex Function		readData()
    Maximum Complexity			22
    Line Number of Deepest Block		472
    Maximum Block Depth			9+
    Average Block Depth			2.97
    Average Complexity			7.00
    Functions				10
    
    --------------------------------------------------------------------------------------------
    Functions:				Complexity, Statements, Max Depth, Calls
    
    deallocateArrayElemsAndArray()		2, 7, 2, 5
    debugOutput()				2, 6, 2, 4
    init()					5, 17, 3, 10
    initDataFiles()				7, 29, 2, 23
    main()					22, 100, 9, 74
    quitapp()				1, 5, 1, 5
    readData()				22, 81, 6, 65
    setDims()				4, 13, 3, 9
    showKbRamAddresses()			3, 9, 3, 5
    traceOutput()				2, 2, 2, 1
    
    --------------------------------------------------------------------------------------------
    Block Depth				Statements
    
    0					53
    1					58
    2					61
    3					26
    4					30
    5					27
    6					41
    7					15
    8					6
    9+					5
    --------------------------------------------------------------------------------------------
    I no longer wish to be associated with this site.
  14. #23
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    That code metrics tool..


    Originally Posted by jwdonahue
    So I got it down to only a pair of functions that exceed a cyclomatic complexity of 15. Note that it has been shown that functions with complexity exceeding 10 harbor something like 90% of all software defects. Experts are generally in agreement that when the cyclomatic complexity exceeds 10, it's fairly difficult to read and understand what the code does. When it exceeds 15 most coders can't hold all the possible execution paths in their head. By the time you get to 20, you're looking to get fired if you work for me; because you're well beyond the complexity that a code reviewer can grok without spending hours or days in that one function.

    It is very difficult to estimate levels of effort to review, document or make modifications to such code. About the only thing you can tell at a glance is that cohesion will be very low and coupling is likely to be very high. So we have three leading indicators that quality is low. Initial tests indicated several symptoms of what could be the same defect or possibly had multiple causes (varying path coverage sometimes yielded the same symptom). When initial stack traces didn't lead to the root cause I decided the only way to tackle the problem was to actually understand the program well enough to simplify it to the point where the defects would be obvious or simply eliminated in the simplification process. Note that in hind sight, I probably could have found one of the defects by laboriously stepping through the code and rationalizing every single state, but that probably would have taken just as long anyway.

    The first step was to add trace and diagnostic output and that required making changes to the program's parameter handling. I collected some trace runs and confirmed my earlier findings in the debugger. I needed to simplify the code to a point where I could confidently remove whole blocks of functionality to figure out which of the pathways were causing issues and still be sure I had a more or less faithful repro of the remaining code. To achieve that I had to reduce the coupling between certain aspects of the program. The first obvious point of attack was the command line argument handling (nearly trivial changes) followed by the data initialization path ways (tumorous/insidious, initially difficult and only half completed at this point).

    I managed to break it down to max complexity in main() at 22 and readData() at 22. I predict there are still latent defects in this code, but I haven't been able to get it to crash using a dozen different data sets and test scenarios (obviously not exhaustive), all of which lead to crashes in the OP's original code (reasonably conclusive). I am fairly certain the behavior regarding the data files is consistent with the original design, but it's hard to say for sure since the only design artifact I have available is a defective code base with no useful comments what-so-ever.

    Note that I worked open loop initially due to the uncertainties. It took nearly 8 hours of effort spread out over several days to get a handle on and fix the bugs. About half that effort involved addition of debug and trace code that should have been part of the original. Now complexity and coupling is reduced and cohesion increased sufficiently that any good software engineer could estimate what the final form of this code should be. IMO, it needs a minimum of 4 to 6 additional functions to get the peak complexity below 15 and probably closer to 10 additional functions to get it down to a peak cyclomatic complexity less than 10. Based on what I have gleaned from the program behavior; I am fairly confident that problem does not require a solution with functions that exceed a complexity metric of 10 and given that it's a stripped down excision from a larger program that will probably do something useful; it probably warrants the additional effort.

    I will post the code when I get my beer from deendee.

    Here's the current code metrics:

    Code:
    Metrics Details For File 'app.cpp'
    --------------------------------------------------------------------------------------------
    
    Parameter				Value
    =========				=====
    Project Directory			...\Projects\Test\app\
    Project Name				testAppCPP
    Checkpoint Name				Checkpoint8
    File Name				app.cpp
    Lines					548
    Statements				322
    Percent Branch Statements		18.3
    Percent Lines with Comments		6.8
    Classes Defined				0
    Methods Implemented per Class		0.00
    Average Statements per Method		0.0
    Line Number of Most Complex Function	221
    Name of Most Complex Function		readData()
    Maximum Complexity			22
    Line Number of Deepest Block		472
    Maximum Block Depth			9+
    Average Block Depth			2.97
    Average Complexity			7.00
    Functions				10
    
    --------------------------------------------------------------------------------------------
    Functions:				Complexity, Statements, Max Depth, Calls
    
    deallocateArrayElemsAndArray()		2, 7, 2, 5
    debugOutput()				2, 6, 2, 4
    init()					5, 17, 3, 10
    initDataFiles()				7, 29, 2, 23
    main()					22, 100, 9, 74
    quitapp()				1, 5, 1, 5
    readData()				22, 81, 6, 65
    setDims()				4, 13, 3, 9
    showKbRamAddresses()			3, 9, 3, 5
    traceOutput()				2, 2, 2, 1
    
    --------------------------------------------------------------------------------------------
    Block Depth				Statements
    
    0					53
    1					58
    2					61
    3					26
    4					30
    5					27
    6					41
    7					15
    8					6
    9+					5
    --------------------------------------------------------------------------------------------


    --- Hello, I am new to this forum,, I was hoping it to find out the name of that tool used for these statistics. I once had that and was using it in a gig I had about 5 years ago. It was great, I have a need for it now on some new code base we adopted, and can't seem to find it on my jump drives and/or Google searches. Thanks in advance.

    Comments on this post

    • clifford disagrees : ... so you resurrected a 9 year old post to ask!? - an needlessly quoted an entire post! Start a new thread and link to this one if necessary.
  16. #24
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Thanks for dissin me.


    Originally Posted by JGG
    --- Hello, I am new to this forum,, I was hoping it to find out the name of that tool used for these statistics. I once had that and was using it in a gig I had about 5 years ago. It was great, I have a need for it now on some new code base we adopted, and can't seem to find it on my jump drives and/or Google searches. Thanks in advance.
    Thanks for dissin me right out of the chute. Would be curious on how you would identify the tool being used w/o the copy/paste of the output from the tool. Here is a bow to you to describe the fields in a generic terms. :tntworth:
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo