Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

No raw arrays in interfaces

ID: cpp/array-in-interfaceKind: problemSecurity severity: Severity: recommendationPrecision: highTags:   - reliability   - readability   - language-features   - external/jsfQuery suites:   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

This rule finds class members (functions or data) that are or use arrays. This is particularly important for functions with array type parameters, as these parameters are treated as pointers to the array’s first element inside the function (array decay). Assuming that it is still has the type of the array passed to the function can cause unexpected behavior (e.g. when using thesizeof operator).

Recommendation

Use theArray class, or explicitly declare the variable/parameter as a pointer so there is no possibility for confusion.

Example

voidf(charbuf[]){//wrong: uses an array as a parameter typeintlength=sizeof(buf);//will return sizeof(char*), not the size of the array passed...}

References


[8]ページ先頭

©2009-2025 Movatter.jp