Good Practice Defects
These defects allow you to observe good coding practices. The defects by themselves might not cause a crash, but they sometimes highlight more serious logical errors in your code. The defects also make your code vulnerable to attacks and hard to maintain. The defects include:
Hard-coded constants such as buffer size and loop boundary
Issues that hinder code readability
Potential coding errors
Missing
const
Polyspace 결과
Ambiguous
declaration syntax | Declaration syntax can be interpreted as object declaration or part of function declaration |
Incorrectly
indented statement | Statement indentation incorrectly makes it appear as part of a block |
Invalid
scientific notation format | the use of an invalid format makes the code less readable (R2022b 이후) |
Line with more than one
statement | Multiple statements on a line |
Duplicated code | A section of code is duplicated in other places (R2023a 이후) |
Partially duplicated code | A section of code is duplicated in other places with very minor changes (R2023a 이후) |
Hard-coded buffer size | Size of memory buffer is a numerical value instead of symbolic constant |
Hard-coded loop boundary | Loop boundary is a numerical value instead of symbolic constant |
Hard-coded object size used to manipulate
memory | Memory manipulation with hard-coded size instead of sizeof |
Method not
const | A method that can be made const is not marked
const (R2022a 이후) |
Public static
field not const | A static and public field of a
struct or class is not marked as a
const (R2022a 이후) |
Unmodified
variable not const-qualified | Variable not const-qualified but variable value not modified
during lifetime |
Macro terminated
with a semicolon | Macro definition ends with a semicolon |
Macro with
multiple statements | Macro consists of multiple semicolon-terminated statements, enclosed in braces or not |
Missing break of switch case |
case block of switch statement does not end in a break, [[fallthrough]] or explanatory comment |
Possibly
inappropriate data type for switch expression |
switch expression has a data type other than char, short, int or
enum |
Semicolon on same
line as if, for or while statement | Semicolon on same line results in empty body of if,
for or while statement |
Delete of void pointer |
delete operates on a void* pointer
pointing to an object |
Missing overload
of allocation or deallocation function | Only one function in an allocation-deallocation function pair is overloaded |
Missing reset of a freed pointer | Pointer free not followed by a reset statement to clear
leftover data |
C++ reference to
const-qualified type with subsequent modification | Reference to const-qualified type is subsequently
modified |
C++ reference
type qualified with const or volatile | Reference type declared with a redundant const or
volatile qualifier |
Declaration of
catch for generic exception | A catch block handles a generic exception that might have many
different subtypes (R2022a 이후) |
Declaration of
throw for generic exception | A function throws a generic exception, which might have many subtypes (R2022a 이후) |
Reference to
un-named temporary | Local reference is declared by using unnamed temporary variable that a function returns by value (R2023a 이후) |
Incorrect syntax of flexible array member size | Flexible array member defined with size zero or one |
Use of a forbidden function | Use of function that appears in a blocklist of forbidden functions |
Use of a forbidden keyword | Use of keyword that appears in a blocklist of forbidden keywords (R2022a 이후) |
Use of a forbidden macro | Use of macro that appears in a blocklist of forbidden macros (R2022b 이후) |
Use of setjmp/longjmp |
setjmp and longjmp cause
deviation from normal control flow |
Bitwise and arithmetic operation on the same
data | Statement with mixed bitwise and arithmetic operations |
File does not
compile | File has a compilation error |
Unused parameter | Function prototype has parameters not read or written in function body |
Unused
variable | Variable defined or declared but not read (R2024a 이후) |
Useless
expressions in sizeof operand |
sizeof operand contains expression that is not
evaluated |
Useless
include | An include directive is present but not used (R2022b 이후) |
도움말 항목
- Bug Finder Defect Groups
Bug Finder defect checkers are classified into groups such as data flow, concurrency, and numerical.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)