sourcepawn icon indicating copy to clipboard operation
sourcepawn copied to clipboard

Add compile warnings for infinite while loops

Open stickz opened this issue 7 years ago • 1 comments

If a while loop uses a counter and has no foreseeable exit condition, I would like a compile warning to be added. This way, the user can correct this error before it crashes their plugin.

void myInfiniteWhileLoop()
{
   int index = 20;
   while (index >=0)
   {
      PrintToChatAll("I like apples");
   }
}

This example may be better suited for a for-loop. But there are other use cases with multiple conditions.

stickz avatar Oct 14 '18 14:10 stickz

There's not a lot we can do here without running into the halting problem. At best, we could detect that the condition was invariant across the loop, which would only be possible if the condition used local variables. That might be worth doing but we're a ways off from being able to do that.

I believe SM enables the watchdog timer, so if you do infinite loop, you should get a timeout after a few seconds.

dvander avatar Jul 19 '21 17:07 dvander