Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix codes that are reported by cppcheck 2.13.0 #1317

Merged
merged 3 commits into from
Jan 6, 2024

Conversation

ma8ma
Copy link
Collaborator

@ma8ma ma8ma commented Jan 6, 2024

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 )
                                                                                      ^

ma8ma added 3 commits January 6, 2024 23:25
ローカル変数のポインターに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 );
                          ^
```
ローカル変数や関数パラメーターの参照に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 )
                                                                                 ^
```
関数の値渡しをするパラメーターを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 )
                                                                                      ^
```
@ma8ma ma8ma added the bug バグの追跡 label Jan 6, 2024
@ma8ma ma8ma merged commit 3409bab into master Jan 6, 2024
20 checks passed
@ma8ma ma8ma deleted the fix-codes-that-are-reported-by-cppcheck-2-13-0 branch January 6, 2024 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug バグの追跡
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

1 participant