Branch coverage and unreachable branches
Task 1
For each example from the section "Statement coverage and unreachable code" (Task 1) of this book, create a Control Flow Graph and identify branches that are unreachable.
- Return Statement Before Print Statement
#include <stdio.h>
int main()
{
printf("text_1");
return 0;
printf("text_2");
}
Unreachable:
-
printf("text_2");
(It comes after thereturn
, so it will never execute.)
2. Infinite Loop Before Statements
if (x == 5)
{
break;
printf("Hello World");
}
Unreachable:
-
printf("Hello World");
(It is placed afterbreak
, so it will never be executed.)
3. Continue Before Print
for (...) {
continue;
printf("Hello World");
}
Unreachable:
-
printf("Hello World");
(zawsze pomijane przezcontinue
)
4. False Condition in if
Statement
double X = 1.55;
if (X > 5) {
X++;
}
return 0;
Unreachable (dla tej konkretnej wartości X):
-
X++;
(ponieważX > 5
jest fałszywe, ciałoif
nie jest wykonywane dla tej wartości; jednak kod sam w sobie nie jest strukturalnie nieosiągalny – jest tylko pomijany w tym przypadku)
Task 2
For each example from the section "Statement coverage and unreachable code" (Task 2) of this book, create a Control Flow Graph and identify branches that are unreachable.