|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CWE-561: Dead Code
Description Summary The software contains dead code, which can never be executed.
Extended Description Dead code is source code that can never be executed in a running program. The surrounding code makes it impossible for a section of code to ever be executed.
Example 1 The condition for the second if statement is impossible to satisfy. It requires that the variables be non-null, while on the only path where s can be assigned a non-null value there is a return statement. (Bad Code) Example
Language: C++ String s = null; if (b) { s = "Yes";
return;
} if (s != null) { Dead();
} Example 2 In the following class, two private methods call each other, but since neither one is ever invoked from anywhere else, they are both dead code. (Bad Code) Example
Language: Java public class DoubleDead { private void doTweedledee() {
doTweedledumb();
}
private void doTweedledumb() {
doTweedledee();
}
public static void main(String[] args) {
System.out.println("running DoubleDead");
}
} (In this case it is a good thing that the methods are dead: invoking either one would cause an infinite loop.) Example 3 The field named glue is not used in the following class. The author of the class has accidentally put quotes around the field name, transforming it into a string constant. (Bad Code) Example
Language: Java public class Dead { String glue;
public String getGlue() {
return "glue";
}
}
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Page Last Updated:
September 12, 2011
|
|
CWE is a Software Assurance strategic initiative co-sponsored by the National Cyber Security Division of the U.S. Department of Homeland Security. This Web site is sponsored and managed by The MITRE Corporation to enable stakeholder collaboration. Copyright © 2006-2012, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation. Contact cwe@mitre.org for more information. |
|||



