MISRA Discussion Forums

Full Version: Question about 14.2 and the controlling variable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

14.2 states that the "controlling variable" must be of essentially boolean type.

Does that mean that the following code is non-compliant?

Code:
struct stuff
{
    uint32_t id;
};
struct stuff stuff_array[MAXSTUFF];

struct stuff* stuff_lookup(uint32_t id)
{
    uint8_t i;
    struct stuff* found = NULL;
    for (i = 0; (i < MAXSTUFF) && (found == NULL); i++) {
        if (stuff_array[i].id == id) {
            found = &(stuff_array[i]);
        }
    }
    return found;
}

Thanks a lot for any help!
Rule 14.2 includes the following statements:
Quote: Second clause which
* shall use the loop counter and optionally loop control flags
Quote: A loop control flag is defined as a single identifier denoting an object with essentially Boolean type that is used in the second clause.
"found" does not meet the criteria for a loop control flag and therefore is non-compliant with rule 14.2
misra-c Wrote:Rule 14.2 includes the following statements:
Quote: Second clause which
* shall use the loop counter and optionally loop control flags
Quote: A loop control flag is defined as a single identifier denoting an object with essentially Boolean type that is used in the second clause.
"found" does not meet the criteria for a loop control flag and therefore is non-compliant with rule 14.2
All right, thanks a lot for the clarification!