페이지 트리

이 페이지의 이전 버전을 보고 있습니다. 현재 버전 보기.

현재와 비교 페이지 이력 보기

버전 1 현재 »






Function-like macros should not be invoked without all of their arguments

Bugcwe, misra, preprocessor

This is a constraint error, but preprocessors have been known to ignore this problem. Each argument in a function-like macro must consist of at least one preprocessing token otherwise the behaviour is undefined.

See
MISRA C:2004, 19.8 - A function-like macro shall not be invoked without all of its arguments.
MITRE, CWE-628 - Function Call with Incorrectly Specified Arguments

Stack allocated memory should not be freed

Bugunpredictable

Stack allocated memory, like memory allocated with the functions alloca, _alloca, _malloca, __builtin_alloca, is automatically released at the end of the function, and should not be released with free. Explicitly free-ing such memory results in undefined behavior.

Noncompliant Code Example

void fun() {
 char *name = (char *) alloca(size);
 // ...
 free(name); // Noncompliant, memory allocated on the stack
 char *name2 = "name";
 // ...
 free(name2); // Noncompliant, memory allocated on the stack
}


Compliant Solution

void fun() {
 char *name = (char *) alloca(size);
 // ...
 char *name2 = "name";
 // ...
}
































































  • 레이블 없음