JDimproved / JDim

2ch browser for linux
https://jdimproved.github.io/JDim/
GNU General Public License v2.0
44 stars 11 forks source link

Fix codes that are reported by cppcheck 2.13.0 #1317

Closed ma8ma closed 6 months ago

ma8ma commented 6 months ago

Add const qualifier to pointer for local variable

ローカル変数のポインターにconstを付けられるとcppcheckに指摘されたため修正します。

cppcheck 2.13のレポート

src/cache.cpp:1122:20: style: Variable 'direntry' can be declared as pointer to const [constVariablePointer]
    struct dirent *direntry;
                   ^
src/jdlib/jdiconv.cpp:138:11: style: Variable 'buf_out_end' can be declared as pointer to const [constVariablePointer]
    char* buf_out_end = out_buf.data() + out_buf.size();
          ^
src/session.cpp:1156:31: style: Variable 'base_view' can be declared as pointer to const [constVariablePointer]
    ARTICLE::ArticleViewBase* base_view = nullptr;
                              ^
src/dbtree/nodetreebase.cpp:3704:31: style: Variable 'tmphead' can be declared as pointer to const [constVariablePointer]
                        NODE* tmphead = res_header( anc_from++ );
                              ^
src/dbtree/nodetreebase.cpp:3785:27: style: Variable 'tmphead' can be declared as pointer to const [constVariablePointer]
                    NODE* tmphead = res_header( from );
                          ^

Add const qualifier to reference for local variable and parameter

ローカル変数や関数パラメーターの参照にconstを付けられるとcppcheckに指摘されたため修正します。

cppcheck 2.13のレポート

src/article/preference.cpp:274:23: style: Variable 'num_str' can be declared as reference to const [constVariableReference]
    for( std::string& num_str : list_res ) {
                      ^
src/cssmanager.cpp:294:82: style: Parameter 'css_pair' can be declared as reference to const [constParameterReference]
CSS_PROPERTY Css_Manager::create_property( std::map< std::string, std::string >& css_pair )
                                                                                 ^

Change function argument type to const reference

関数の値渡しをするパラメーターをconst referenceにできるとcppcheckに指摘されたため修正します。

cppcheck 2.13のレポート

src/jdlib/miscutil.cpp:1846:75: performance: Parameter 'list_str' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++. [passedByValue]
std::vector< std::string > MISC::recover_path( std::vector< std::string > list_str )
                                                                          ^
src/viewfactory.cpp:29:87: performance: Parameter 'view_args' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++. [passedByValue]
SKELETON::View* CORE::ViewFactory( int type, const std::string& url, VIEWFACTORY_ARGS view_args )
                                                                                      ^