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 array bounds checking #307

Merged
merged 1 commit into from May 30, 2020
Merged

Conversation

ma8ma
Copy link
Collaborator

@ma8ma ma8ma commented May 30, 2020

配列にアクセスした後で境界のチェックをしているとcppehckに指摘された箇所があったため条件の順序を修正します。

cppcheckのレポート

src/dbtree/nodetreejbbs.cpp:240:29: style: Array index 'pos' is used before limits check. [arrayIndexThenCheck]
            while( lines[ pos ] != '\n' && pos < byte_lines ) ++pos;
                        ^
src/dbtree/nodetreebase.cpp:1772:15: style: Array index 'i' is used before limits check. [arrayIndexThenCheck]
while( str[ i ] != 's' && i < lng ) ++i;
          ^
src/jdlib/misctrip.cpp:129:33: style: Array index 'n' is used before limits check. [arrayIndexThenCheck]
            for( n = 17; key[n] && n < 19; ++n )
                            ^
src/jdlib/miscutil.cpp:139:16: style: Array index 'i' is used before limits check. [arrayIndexThenCheck]
    if( str[ i ] == '\"' && (i < 1 || str[ i -1 ] != '\\') ){
           ^

配列にアクセスした後で境界のチェックをしているとcppehckに指摘された
箇所があったため条件の順序を修正します。

cppcheckのレポート
```
src/dbtree/nodetreejbbs.cpp:240:29: style: Array index 'pos' is used before limits check. [arrayIndexThenCheck]
                while( lines[ pos ] != '\n' && pos < byte_lines ) ++pos;
                            ^
src/dbtree/nodetreebase.cpp:1772:15: style: Array index 'i' is used before limits check. [arrayIndexThenCheck]
    while( str[ i ] != 's' && i < lng ) ++i;
              ^
src/jdlib/misctrip.cpp:129:33: style: Array index 'n' is used before limits check. [arrayIndexThenCheck]
                for( n = 17; key[n] && n < 19; ++n )
                                ^
src/jdlib/miscutil.cpp:139:16: style: Array index 'i' is used before limits check. [arrayIndexThenCheck]
        if( str[ i ] == '\"' && (i < 1 || str[ i -1 ] != '\\') ){
               ^
```
@ma8ma ma8ma added the bug バグの追跡 label May 30, 2020
@ma8ma ma8ma merged commit 9afd7fb into JDimproved:master May 30, 2020
@ma8ma ma8ma added this to Done in State of JDim-v0.3.0+ via automation May 30, 2020
@ma8ma ma8ma deleted the fix-array-bounds-checking branch May 30, 2020 07:05
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.

None yet

1 participant