language agnostic - Technical non-terminating condition in a loop -


Most of us know that there should not be a non-terminating condition in a loop. For example, there is a non-termination status in this C # loop: i of any value i is a clear logic error.

  Zero CountByTwosStartingAt (byte i) {// If I am also, then it does not exceed 254 for (; i & lt; 255; i + = 2) {console .WriteLine (I); }}  

Sometimes there are cases of edges that are extremely unlikeley, but technically non-exit status (Stack overflow and out-of-memory errors on one side) would be formed is. Suppose you have a function that is the number of sequential zeros in the curve counts:

  int CountZeros (stream) {int total = 0; While (s.ReadByte () == 0) Total ++; Total return; }  

Now, suppose you feed this thing to:

  class InfiniteEmptyStream: stream {// ... other members ... public Read override int (byte [] buffer, int offset, int count) {array. Clear (buffer, offset, count); // Number of output return zero; // Never Return -1 (End of Stream)}}  

Or more realistically, possibly a stream that gives data from external hardware, in which case too many zeros (eg A game controller is sitting at your desk) In some way we have an infinite loop, this is particularly the case of non-termination, but occasionally not .

An example of a completely real world as an app, I'm writing an empty stream of zero in empty "empty" objects will be emptied (unless the collection class or the GC throws an exception Because I have crossed over two billion items). But this would be a completely unpredictable situation (considering my data source).

How important is it really for any non-terminating situations? How much does it affect "strength"? Does it matter if they are not just finished "theoretically" (is it okay if an exception represents an inherent ending position)? Is it a matter of whether the app is commercial? If it is distributed publicly? Is there anything to talk about if the problematic code is not accessible through a public interface / API?

Edit: One of my primary concerns can cause unconstrained logic errors which are non-termination status, as a rule, you ensure that someone There is no non-termination status, you can identify or handle more of these logic errors, but is it worth it? And when? This is a matter of concern for you.

Whether you rely on your data source, t

If you trust it, then you probably want to make the best effort to process the data, even if it is. If it sends you a zero for ever, then it is a big problem to solve your resources, and you use it all of your resources and fails you say that it is "completely unexpected" So the question is whether it is okay for you to be "completely unexpected", because it is out of memory or is it really impossible to be?

If you do not rely on your data source, then you probably want to put an artificial limit on the size of the problem, before you run out of system memory that fails

In any case it may be possible to write your app in a manner that you improve with an out-of-memory exception.

It is a strong issue in any way, but due to the fall, the problem is too big to solve (your task is impossible) is generally considered more acceptable than falling because some malicious users will give you zero Is sending a stream of (you have accepted some script-kiddy doos impossible job from the attacker).


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

jquery - SimpleModal Confirm fails to submit form -