Solved

Detect infinite loops via software

Posted on 2007-11-27
8
980 Views
Last Modified: 2008-03-29
Is there any software product that can detect potential infinite loops in  your code? In other words, something like an editor that I can open up (I use .NET) a .cs file and it would, say, underline any code (or something like that) that could potentially cause infinite loops?
0
Comment
Question by:jeremyduj
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20361382
there are hundreds of situations where you cannot detect infinite loop until program is running and some variables are set. This is a lazzy and inaccurate approach, better you focus in becoming a good programmer.
0
 
LVL 1

Author Comment

by:jeremyduj
ID: 20361498
that was a pretty useless comment.
0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 20363401
Consider the following:
while (!otherThreadComplete)
   sleep(1000);
// Now do something useful.

What happens if something blocks the other thread. This is reasonable code, but is a potential infinite loop. While it would be possible to detect a missing index incrementor in a simple loop, many loops involve variables and methods of other objects.

Because of the complexity of trying to obtain reasonable code coverage, I do not think anyone has made the attempt. I have certainly never seen one.

Jim
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20365272
Hmm, well I'm not sure about C# but certainly C++ has a number of tools that can be used at build time to detect and report such possibilities (such as Coverity).

That said, as useless as you think the comment by @jaime_olivares is (I don't!) he does, in fact, raise a perfectly valid point! For example, say you read in a variable from a config file and your loop exit is predicated on a specific value of that config. It is conceivable that your code will enter an infinite loop unchecked. It is possible that a tool may not spot that and, as such, it is better to code defensively against such possibilities.

The way a lot of professional software companies try to mitigate against such situations is to implement code reviews. Basically, the source code is checked into a central review repository (such as CodeStriker) and reviewed by other developers. Comments are actioned and the process repeated until all reviewers are satisfied that the code is fit for purpose.

-Rx.

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:jeremyduj
ID: 20366208
Well, I literally have about 10 running applications on the web server and I didn't write all the code for every single program, so I'm really not sure where the infinite loop is coming from. There are literally hundreds of thousands of lines of code ... just trying to find a quicker approach than to go through thousands of lines of code looking for a loop! Actually, have you guys tried looking at this program here http://www.iistools.com/en/iisguard.html - it monitors IIS and may be able to pinpoint what page of what program is causing the infinite loop... I'm going to go ahead and install this and perhaps I'll be able to find the culprit! But of course this requires that I await the next infinite loop - and everybody goes crazy at work because the applications are running too slow. I was thinking before that if I could run every .cs file through some kind of editor, that it could pick up potential infinite loops such as something extremely simple as While(1) - even though its simple to fix, you have to pinpoint that one line of code in about 100 .cs files that all have 5000 lines of code or more!  I'll keep looking. Thanks.
0
 
LVL 22

Accepted Solution

by:
JimBrandley earned 500 total points
ID: 20366825
Can you duplicate the problem running through the debugger? If so, you can just break and check the call stack when you are pretty sure you are in it. Another way to detect it would be to start the app in a profiler (we use Ants from Redgate). After it runs for a time and you have encountered the loop problem, a snapshot will allow you to see the code that's executing more frequently than it should.

Jim
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20367125
>> something extremely simple as While(1) - even though its simple to fix,
Not necessarily! The body of the while loop may be very complex and contain numerous break and continue clauses (not that I advocate such heinous code)!

0
 
LVL 7

Expert Comment

by:photowhiz
ID: 20367180
What you are asking for is mathematically impossible: http://en.wikipedia.org/wiki/Halting_problem
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
.Net application crashing 6 20
VB.NET HttpWebRequest 12 30
Different Delete Messages 7 10
Getfiles in vb.net 21 0
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now