JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.0p0 Hot Tips | CONFIDENTIAL | CodeSecure Inc |
A loop does not have a fixed bound. (For more information, see the notes below.)
| Class Name | Potential Unbounded Loop | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | style | ||||||||||||||||||
| Mnemonic | LANG.STRUCT.LOOP.UB | ||||||||||||||||||
| Categories |
|
||||||||||||||||||
| Availability | Available for C and C++. |
||||||||||||||||||
| Enabling | Checks for this warning class are
disabled by default. To enable them, add the following WARNING_FILTER
rule to the project configuration file.
WARNING_FILTER += allow class="Potential Unbounded Loop" |
#include <stdlib.h>
void lang_struct_loop_ub (void){
int i = 0;
while (rand()) { /* 'Potential Unbounded Loop' warning issued here */
if (i++ == 10) {break;}
}
}
CodeSonar will issue an Unbounded Loop warning if it cannot identify a loop counter whose value is updated and tested in a way that guarantees that the loop will executed a bounded number of times. This means that the following must all hold.
Variables whose value is tested in the loop condition with one of {<, <=,>, >=} are called candidate loop counters. If there are one or more candidate loop counters but none of them satisfies all the required conditions, CodeSonar will report each candidate considered along with the reason that it is not suitable for demonstrating boundedness.
Use the NON_TERMINATING_LOOP_MARK configuration file parameter to specify loops that should not trigger a Potential Unbounded Loop warning. For example, this can be useful if you use constructs like for(;;){...} and while(1){...} and wish to continue to do so, or if you wish to be able to add special code comments to identify loops to exclude from this check.
The following configuration file parameters affect checks for this warning class.