요약: C-style pointer casting

내용: C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected. See also: https://www.securecoding.cert.org/confluence/display/cplusplus/EXP05-CPP.+Do+not+use+C-style+casts.

static_cast, const_cast 로 바꾸는걸 권장(reinterpret_cast는 사용하지 않는걸 권장)

void* 를 struct*로 바꾸려면 ((struct 구조체 이름*)변수)로 바꿀것(reinterpret_cast 사용 하지 말고)

저렇게 바꾸면 cppcheck에 C-style포인터 캐스팅이라고 안뜸


요약: Prefer prefix ++/-- operators for non-primitive types.

내용: Prefix ++/-- operators should be preferred for non-primitive types. Pre-increment/decrement can be more efficient than post-increment/decrement. Post-increment/decrement usually involves keeping a copy of the previous value around and adds a little extra code.

후위증가를 전위증가로 바꾸는걸 권장

effective c++에도 나옴


요약: The class does not have a constructor.

내용: The class does not have a constructor although it has private member variables. Member variables of builtin types are left uninitialized when the class is instantiated. That may cause bugs or undefined behavior.

초기화 해야 할 변수가 있는데 생성자를 만들지 않았고 그래서 초기화 되지도 않았음.

cppcheck는 소멸자는 체크하지 않기 때문에 생성자를 만들때 소멸자도 쌍으로 같이 만들어 주면 좋겠지..



요약: Checking if unsigned variable 'size' is less than zero.

내용: The unsigned variable 'size' will never be negative so it is either pointless or an error to check if it is.

unsigned값은 항상 0보다 큰데 0보다 작은지 체크하지 않았다. 

사용하기 전에 항상 0보다 큰값인지 체크해야 한다


요약: Class '클래스 이름' has a constructor with 1 argument that is not explicit.

내용: Class '클래스 이름' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided.

암시적 형변환을 막기 위한 키워드 http://opensw.wikidot.com/cpp-fundamentals-explicit



요약: Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant.

내용: The conversion from const char* as returned by c_str() to std::string creates an unnecessary string copy. Solve that by directly passing the string.

c_str()로 변수를 전달하는게 매우 느리다고 경고

string째로 넘기든지 해라..



요약: Using memset() on union which contains a floating point number.

내용: Using memset() on union which contains a floating point number. This is not portable because memset() sets each byte of a block of memory to a specific value and the actual representation of a floating-point value is implementation defined. Note: In case of an IEEE754-1985 compatible implementation setting all bits to zero results in the value 0.0.

memset시 float가 들어있는 struct는 초기화가 안됨 http://stackoverflow.com/questions/27581320/using-memset-in-double-type-array

fill로 해줘야함(아니면 부동소수점 문제가 생김)


요약: Function parameter 'title' should be passed by reference.

내용: Parameter 'title' is passed by value. It could be passed as a (const) reference which is usually faster and recommended in C++.








'C++' 카테고리의 다른 글

rand  (0) 2017.02.20
int to string, int to char*  (0) 2016.12.02
Winapi 그림판 색 고르기  (0) 2016.06.23
rxcpp::observable<void, void>::create의 인스턴스가 없습니다.  (0) 2016.05.03
RxCpp 설치하기  (0) 2016.05.03

+ Recent posts